Accessing 'data' argument of with() function?

Posted by Ken Williams on Stack Overflow See other posts from Stack Overflow or by Ken Williams
Published on 2010-03-12T23:15:30Z Indexed on 2010/03/12 23:17 UTC
Read the original article Hit count: 192

Filed under:

Is it possible, in the expr expression of the with() function, to access the data argument directly? Here's what I mean conceptually:

> print(df)
 result qid     f1     f2     f3
     -1   1 0.0000 0.1253 0.0000
     -1   1 0.0098 0.0000 0.0000
      1   1 0.0000 0.0000 0.1941
     -1   2 0.0000 0.2863 0.0948
      1   2 0.0000 0.0000 0.0000
      1   2 0.0000 0.7282 0.9087
> with(df, subset(.data, select=f1:f3))  # Doesn't work

Of course the above example is kind of silly, but it would be handy for things like this:

with(subset(df, f2>0), foo(qid, vars=subset(.data, select=f1:f3)))

I tried to poke around with environment() and parent.frame() etc., but didn't come up with anything that worked.

Maybe this is really a question about eval(), since that's how with.default() is implemented.

© Stack Overflow or respective owner

Related posts about r