[R] Tying to underdressed the magic of lm redux

Berry, Charles ccberry @end|ng |rom uc@d@edu
Sun Jun 2 05:23:23 CEST 2019


I believe the pieces you are missing are filed under 'computing on the language', 'passing unevaluated objects', and 'language objects'.

Forgive me if I belabor things you already know.  

lm, transform, and many other functions do their "magic" by operating on language objects.

You might find a read of the `Computing on the Language' section in Venables and Pipley's `S Programmming' useful aa background. There are probably many blogs and other on-line resources, too.

The unquoted things you want to operate on are language objects. deparse-ing those objects and trying to operate on character strings is one way to deal with such objects, but it can get messy.  

You might find that `transform.data.frame' provides a useful example of how to deal with language objects provided as arguments to a function.

I suggest you try `debugonce' on lm and on `transform.data.frame'. Run an example of each and inspect each object created along the way. 

For lm, you should aim to understand everything through this line: 

 mf <- eval(mf, parent.frame()) 

Getting familiar with `substitute', `match.call', `eval', and friends will help.



p.s. It sounds like what you want to do is to extend `transform.data.frame' in some way. ??

> On Jun 1, 2019, at 6:43 PM, Sorkin, John <jsorkin using som.umaryland.edu> wrote:
> Colleagues,
> Despite Bert having tried to help me, I am still unable to perform a simple act with a function. I want to pass the names of the columns of a dataframe along with the name of the dataframe, and use the parameters to allow the function to access the dataframe and modify its contents.
> I apologize multiple postings regarding this question, but it is a fundamental concept that one who wants to program in R needs to know.
> T

More information about the R-help mailing list