# Capture call environment in Weave.jl?

**URL:** <https://discourse.julialang.org/t/capture-call-environment-in-weave-jl/47616>\
**Category:** New to Julia\
**Created:** [October 1, 2020, 7:44pm UTC](https://discourse.julialang.org/t/capture-call-environment-in-weave-jl/47616 "2020-10-01T19:44:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![conditionality](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@conditionality](https://discourse.julialang.org/u/conditionality)\
**Post date:** [October 1, 2020, 7:44pm UTC](https://discourse.julialang.org/t/capture-call-environment-in-weave-jl/47616/1 "2020-10-01T19:44:37Z")

</div>

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:

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

```

report.jmd:

```julia

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?

---

<div class="post-metadata">

**Author:** ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Post date:** [October 1, 2020, 8:26pm UTC](https://discourse.julialang.org/t/capture-call-environment-in-weave-jl/47616/2 "2020-10-01T20:26:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Post date:** [October 1, 2020, 8:28pm UTC](https://discourse.julialang.org/t/capture-call-environment-in-weave-jl/47616/3 "2020-10-01T20:28:49Z")

</div>

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

`generate_report.jl`:

```julia
module MyMod
    my_dataframe = get_statistics()
end # end module

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

```

`report.jmd`:

```julia
plot(my_dataframe)

```
