Chaehan So
2010-Feb-10 19:28 UTC
[R] eval function with javascript-semantics possible in R?
Dear r-helpers,
I am looking for an R-equivalent for the eval-function in javascript which
can
interpret a string as code on runtime, thereby allowing things like
for (i in c(1:2))
{
eval(items + "i") <- read.csv(eval(filename+ i),
dec=",");
}
which would execute (with filename="testfile"):
items1 <- read.csv(testfile1, dec=",");
items2 <- read.csv(testfile2, dec=",");
The way I intend to use it is to define a string list containing names of
date.frames,
and interate this list to perform some function:
createTable <- function(latentVariableNames)
{
for (currentName in names(latentVariableNames))
{
doSomethingWith(currentName)
}
}
Would be grateful for any help!
Chaehan
[[alternative HTML version deleted]]
Henrique Dallazuanna
2010-Feb-10 19:36 UTC
[R] eval function with javascript-semantics possible in R?
Try this: fileName <- "testfile%s" lapply(sprintf(fileName, 1:2), read.csv, dec = ",") On Wed, Feb 10, 2010 at 5:28 PM, Chaehan So <chaehan.so at gmail.com> wrote:> Dear r-helpers, > > I am looking for an R-equivalent for the eval-function in javascript which > can > interpret a string as code on runtime, thereby allowing things like > > for (i in c(1:2)) > { > > eval(items + "i") <- read.csv(eval(filename+ i), dec=","); > > } > > which would execute (with filename="testfile"): > > items1 <- read.csv(testfile1, dec=","); > items2 <- read.csv(testfile2, dec=","); > > > The way I intend to use it is to define a string list containing names of > date.frames, > and interate this list to perform some function: > > createTable <- function(latentVariableNames) > { > for (currentName in names(latentVariableNames)) > { > doSomethingWith(currentName) > ?} > } > > > Would be grateful for any help! > > Chaehan > > ? ? ? ?[[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