[R] How to findout the name of a dataframe

jim holtman jholtman at gmail.com
Sun Feb 17 18:48:53 CET 2013


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.



More information about the R-help mailing list