Capture call environment in Weave.jl?

I have some code that computes a bunch of statistics and I would like to compile all of those statistics into a report. I could manually construct such a report.html file by printing plots and data to the file, but I imagine there should be an easier way. So searching around, I managed to find Weave.jl.My interpretation was that I will create sort of a template “report.jmd” and when I execute weave(“report.jmd”) from generate_report.jl, then report.jmd should be able to capture variables from generate_report.jl. This does not seem to work. Some pseudo-code:

generate_report.jl:

my_dataframe = get_statistics()
weave("report.jmd")

report.jmd:


plot(my_dataframe ) #<-- ERROR: UndefVarError: my_dataframe not defined

Is there anyway to make this work or is Weave the wrong approach for me? What to use then?

1 Like

You can pass an environment in to Weave.

Check out the mod keyword argument.

So maybe in your “generate” script, you can do everything inside some module MyMod.

And then pass that module to Weave

1 Like

I haven’t run this code, but this is the general idea:

generate_report.jl:

module MyMod
    my_dataframe = get_statistics()
end # end module

weave("report.jmd"; mod = MyMod)

report.jmd:

plot(my_dataframe)
1 Like