# Behavior of @df inside a function

**URL:** https://discourse.julialang.org/t/behavior-of-df-inside-a-function/40262
**Category:** New to Julia
**Created:** [May 27, 2020, 3:18pm UTC](https://discourse.julialang.org/t/behavior-of-df-inside-a-function/40262 "2020-05-27T15:18:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)
#### Post date: [May 27, 2020, 3:18pm UTC](https://discourse.julialang.org/t/behavior-of-df-inside-a-function/40262/1 "2020-05-27T15:18:10Z")

</div>

Consider the function and a call to this function. Notice the placement of @df on the first line of myPlot().  
There is a spae before the @df macro. Everything runs fine. However, if I remove this space, then when compiling myPlot in Atom, I get the error that df\_jump is not defined. I understand that the macro executes before the call to the function, so it is expanding on something that is not defined. But if this is true, why does adding a space before the @ symbol solve the problem? I do not understand. Thanks.

```julia
function run_plot(tot_pop)
  	prop_infected = 0.001
 	I0 = floor(Int, tot_pop * prop_infected)
 	S0 = tot_pop - I0
  	u0 = [S0,I0,0];
	prob = DiscreteProblem(u0,tspan)
	prob_jump = JumpProblem(prob,Direct(),sir_model)
	sol_jump = solve(prob_jump,SSAStepper());
	out_jump = sol_jump(t);
	df_jump = DataFrame(out_jump')
	df_jump[!,:t] = out_jump.t;
    myPlot(df_jump)
end

function myPlot(df_jump)
 @df df_jump plot(:t,
    [:x1 :x2 :x3],
    label=["S" "I" "R"],
    xlabel="Time",
    ylabel="Number")
end

time run_plot(10000)

```

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [May 27, 2020, 5:03pm UTC](https://discourse.julialang.org/t/behavior-of-df-inside-a-function/40262/2 "2020-05-27T17:03:19Z")

</div>

That’s extremely odd. A leading space in front of the `@` should have no effect.

It’s hard to diagnose the real problem from the example that you’ve given because your code relies on a bunch of external functions, variables, and packages, and it’s not clear what exactly those are.

The first thing I would do is find a _minimal_, _reproducible_ example that shows the same problem. I would start by removing all the code that sets up and solves the problem in `run_plot` and replacing it with a dummy `DataFrame`.

---

<div class="post-metadata">

### Author: ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)
#### Post date: [May 27, 2020, 5:20pm UTC](https://discourse.julialang.org/t/behavior-of-df-inside-a-function/40262/3 "2020-05-27T17:20:08Z")

</div>

### Gordon Erlebacher \<[Gerlebacher@fsu.edu](mailto:Gerlebacher@fsu.edu)\>

1:18 PM (1 minute ago)

![](https://global.discourse-cdn.com/julialang/original/3X/5/6/56d45f8a17f5078a20af9962c992ca4678450765.gif)  
 ![](https://global.discourse-cdn.com/julialang/original/3X/5/6/56d45f8a17f5078a20af9962c992ca4678450765.gif)

to **JuliaLang**  
 ![](https://global.discourse-cdn.com/julialang/original/3X/5/6/56d45f8a17f5078a20af9962c992ca4678450765.gif)

I will create a minimal example and see if this happens with my setup in general.  
But I agree this should not happen. I thought a MWE would help, but I was hoping that something would jump out. Thanks.
