Skip to content
Prev 33963 / 63424 Next

Problem using model.frame with argument subset in own function

Gavin,

I ran into the same cryptic "invalid subscript type 'closure'" message in
a slightly less complicated scenario, and wanted to post the cause in 
my case (the root cause is probably the same either way).

Similarly to your case, I was subsetting a data frame. I had a list
of variable names corresponding to columns in the frame. 
Unfortunately the variable name I had assigned to this list, var, 
coincided with the name of a base package function in R for variance.

When I attempted to subset df[, var], I got the 'closure' error message,
but if I renamed the list of variable names so the collision didn't occur,
e.g. df[, vars] instead of df[, var], it worked as expected.

Sincerely, 
Greg B. Hill
Gavin Simpson wrote: