1

Often functions that work with data.frames have the ability to let the user provide a dataset, so that the user can use its columns in a straight forward way. E.g.:

lm(mpg~cyl+gear,data=mtcars)

Instead of using mtcars$cyl in the formula, we can simply use cyl. How can I implement such behavior in custom built functions?

5
  • 3
    You can always look at the source of lm and see what's going on, or this wiki by Hadley may be of interest: github.com/hadley/devtools/wiki/Evaluation Commented Jan 12, 2012 at 15:26
  • very nice. thx Chase and James . Sometimes i just seem to forget about nice things... Commented Jan 12, 2012 at 15:41
  • Another good place to look for a worked example is the subset.data.frame function code. Commented Jan 12, 2012 at 17:28
  • Here was my answer to a recent ~ identical question: stackoverflow.com/questions/8484664/… Commented Jan 12, 2012 at 17:59
  • +1 on that other thread for you Josh, I think i am finally gettin started with other environments but global. Thx for the more elaborate answer though. Commented Jan 12, 2012 at 18:04

1 Answer 1

1

There are several different techniques for this, described in Standard nonstandard valuation rules.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.