Iterating on regressions using GLM

Ok this was helpful but I’m very confused by the whole thing. If I run

data = DataFrame(x=[2,3],y=[3,6])
r = :x
@eval temp=glm(@formula(y ~ $r), data, Normal(), IdentityLink())

everything works, no problem. However, the following throws an error

function foo()
       data2 = DataFrame(x=[2,3],y=[3,6])
       r2 = :x
       @eval temp=glm(@formula(y ~ $r2), data2, Normal(), IdentityLink())
end
foo()

The outcome is

ERROR: UndefVarError: data2 not defined

What’s going on?