[R] Transforming a string to a variable's name? help me newbie...

David Winsemius dwinsemius at comcast.net
Mon Dec 8 16:39:08 CET 2008

On Dec 8, 2008, at 10:11 AM, tsunhin wong wrote:

> Dear all,
> I'm a newbie in R.
> I have a 45x2x2x8 design.
> A dataframe stores the metadata of trials. And each trial has its own
> data file: I used "read.table" to import every trial into R as a
> dataframe (variable).
> Now I dynamically ask R to retrieve trials that fit certain selection
> criteria, so I use "subset", e.g.
> tmptrialinfo <- subset(trialinfo, (Subject==24 & Filename=="v2msa8"))
> The name of the dataframe / variable of an individual trial can be
> obtained using:
> paste("t",tmptrialinfo[1,2],tmptrialinfo[1,16],".gz",sep="")
> Then I get a string:
> "t24v2msa8.gz"
> which is of the exact same name of the dataframe / variable of that
> trial, which is:
> t24v2msa8.gz

> Can somebody tell me how can I change that string (obtained from
> "paste()" above) to be a usable / manipulable variable name, so that I
> can do something, such as:
> (1)
> tmptrial <- trialcompute(trialextract(
> paste("t",tmptrialinfo[1,2],tmptrialinfo[1,16],".gz",sep="")
> ,tmptrialinfo[1,32],secs,sdm),secs,binsize)
> instead of hardcoding:
> (2)
> tmptrial <-  
> trialcompute 
> (trialextract(t24v2msa8.gz,tmptrialinfo[1,32],secs,sdm),secs,binsize)

It may have something to do with the semantics of trialextract about  
which most useRs will know nothing (and I was unsuccessful in finding  
a function by that name with an Rsitesearch). It seems strange that a  
function would accept an unquoted reference to what is obviously a  
file name. Perhaps you should be offering that code for inspection  
rather than asking how to make a simple assignment. It is possible  
that what you are really asking is answered by Faq 7.21:


> Currently, 1) doesn't work...

Saying "doesn't work" is not specific enough. What exactly was the  
error message?
> Thanks in advance for your help!
> Regards,
>      John
> ______________________________________________
> 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.

More information about the R-help mailing list