[R] Obtaining name of data frame used in a function argument

Henrique Dallazuanna wwwhsd at gmail.com
Thu Mar 11 18:47:32 CET 2010


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



More information about the R-help mailing list