Jason Baucom
2010-Mar-11 17:31 UTC
[R] Obtaining name of data frame used in a function argument
I'm writing a function that can take a data.frame as an argument. I'd like to be able to obtain the name of the data.frame and print it out within the function. My current function looks like this: examineIt<-function(x) { print(nrow(x)) print(x[ceiling(runif(10)*nrow(x)),]) print(summary(x)) } examineIt(myDataFrame) I'd like for the function to also output "myDataFrame". Is there any way to do this? I'm running this function several times in a row and need to be able to identify which data.frame was analyzed. Thanks! Jason [[alternative HTML version deleted]]
Henrique Dallazuanna
2010-Mar-11 17:47 UTC
[R] Obtaining name of data frame used in a function argument
Try this: foo <- function(data)print(deparse(substitute(data))) foo(DF) On Thu, Mar 11, 2010 at 2:31 PM, Jason Baucom <jason.baucom at ateb.com> wrote:> I'm writing a function that can take a data.frame as an argument. I'd > like to be able to obtain the name of the data.frame and print it out > within the function. My current function looks like this: > > > > examineIt<-function(x) { > > print(nrow(x)) > > print(x[ceiling(runif(10)*nrow(x)),]) > > print(summary(x)) > > } > > > > examineIt(myDataFrame) > > > > I'd like for the function to also output "myDataFrame". Is there any way > to do this? I'm running this function several times in a row and need to > be able to identify which data.frame was analyzed. > > > > Thanks! > > Jason > > > ? ? ? ?[[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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Apparently Analagous Threads
- generating multiple sequences in subsets of data
- obtaining exact p-values in mixed effects model
- dput/dget when a data frame has 2 rows (PR#9627)
- Error in file(fname, "r") : invalid 'description' argument when running maptools' readAsciiGrid on a dataframe
- subset on data frame