Let'say we have a dataframe mydata with column v1. If mydata$v1 is passed to a function, is there way, then, to extract the name of the dataframe? What I now do is passing the name of the dataframe to the funcion, so passing two parameters. Maybe with mydata$v1 it is not possible, but with mydata['v1'] or mydata[,'v1'] it is? Thanks Frans ------------------- Frans Marcelissen fransiepansiekevertje@gmail.com [[alternative HTML version deleted]]
Will this work for you:> myFunc <- function(var){+ # get the dataframe name + charName <- deparse(substitute(var)) + # parse out data.frame + dataFrame <- sub("\\$.*", "", charName) + cat("input:", charName, "data.frame:", dataFrame, "\n") + }> > myFunc(mydata$V1)input: mydata$V1 data.frame: mydata> >On Sun, Feb 17, 2013 at 8:51 AM, Frans Marcelissen <frans.marcelissen at digipsy.nl> wrote:> Let'say we have a dataframe mydata with column v1. If mydata$v1 is passed > to a function, is there way, then, to extract the name of the dataframe? > What I now do is passing the name of the dataframe to the funcion, so > passing two parameters. Maybe with mydata$v1 it is not possible, but with > mydata['v1'] or mydata[,'v1'] it is? > Thanks > Frans > > ------------------- > Frans Marcelissen > fransiepansiekevertje at gmail.com > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
On Feb 17, 2013, at 5:51 AM, Frans Marcelissen wrote:> Let'say we have a dataframe mydata with column v1. If mydata$v1 is passed > to a function, is there way, then, to extract the name of the dataframe? > What I now do is passing the name of the dataframe to the funcion, so > passing two parameters. Maybe with mydata$v1 it is not possible, but with > mydata['v1'] or mydata[,'v1'] it is?It will depend on the specifics. The usual way is with deparse(substitute(arg))> d <- data.frame(a="a")> gn <- function(col) print(deparse(substitute(col))) > gn(d)[1] "d"> gn(d$a)[1] "d$a" You do realize that mydata$v1 is identical (after evaluation, anyway) to mydata[,'v1'] , but not to mydata['v1'], don't you?> gn(d['a'])[1] "d[\"a\"]"> Thanks > Frans > > ------------------- > Frans Marcelissen > fransiepansiekevertje at gmail.com > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA