Re: [R] Write a function that allows access to columns of a passeddataframe.

2016-12-06 Thread Bert Gunter
Simpler I think: ?all.vars > all.vars(~A+B) [1] "A" "B" Note also: > all.vars(~log(A)) [1] "A" Cheers, Bert "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Dec

Re: [R] Write a function that allows access to columns of a passeddataframe.

2016-12-06 Thread David Winsemius
> On Dec 6, 2016, at 7:33 AM, Rui Barradas wrote: > > Perhaps the best way is the one used by library(), where both > library(package) and library("package") work. It uses > as.charecter/substitute, not deparse/substitute, as follows. > > mydf <- > data.frame(id=c(1,2,3,4,5),sex=c("M","M","M

Re: [R] Write a function that allows access to columns of a passeddataframe.

2016-12-06 Thread Rui Barradas
Perhaps the best way is the one used by library(), where both library(package) and library("package") work. It uses as.charecter/substitute, not deparse/substitute, as follows. mydf <- data.frame(id=c(1,2,3,4,5),sex=c("M","M","M","F","F"),age=c(20,34,43,32,21)) mydf class(mydf) str(mydf) myf

Re: [R] Write a function that allows access to columns of a passeddataframe.

2016-12-06 Thread Rui Barradas
Ok, that's a way of seeing it. Rui Barradas Em 06-12-2016 14:28, John Sorkin escreveu: Over my almost 50 years programming, I have come to believe that if one wants a program to be useful, one should write the program to do as much work as possible and demand as little as possible from the user

Re: [R] Write a function that allows access to columns of a passeddataframe.

2016-12-06 Thread William Dunlap via R-help
Note that library has another argument, character.only=TRUE/FALSE, to control whether the main argument should be regarded as a variable or a literal. I think you need two arguments to handle this. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 6, 2016 at 7:33 AM, Rui Barradas wrote:

Re: [R] Write a function that allows access to columns of a passeddataframe.

2016-12-06 Thread William Dunlap via R-help
I basically agree with Rui - using substitute will cause trouble. E.g., how would the user iterate over the columns, calling your function for each? for(column in dataFrame) func(column) would fail because dataFrame$column does not exist. You need to provide an extra argument to handle this

Re: [R] Write a function that allows access to columns of a passeddataframe.

2016-12-06 Thread John Sorkin
Over my almost 50 years programming, I have come to believe that if one wants a program to be useful, one should write the program to do as much work as possible and demand as little as possible from the user of the program. In my opinion, one should not ask the person who uses my function to re