How to integrate a dynamic code within a R script?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to integrate a dynamic code within a R script?

lucameyer
Hi,

I am working on a script which should includes a dynamic listing, i.e.

# SCRIPT BEGINS

# some R procedures here

# DYNAMIC PART BEGINS
d1$X5 <-f1("AAA")
d1$X5 <-f1("AAa")
d1$X5 <-f1("ABa")
# etc...
d1$X6 <-f2("AAA")
d1$X6 <-f2("AAs")
d1$X6 <-f2("ABs")
# etc...
# DYNAMIC PART ENDS

# other procedures here

# SCRIPT ENDS

Basically I have an Excel page with a quite long listing of "AAA", "AAa",
"ABa", "ccc", "Ded", etc, one entry on each line. The listing is likely to
change over time and the script will run at least once a day.

My initial planning was to do something like

f1 <- read.xlsx("LIST.xlsx",1, startRow=2, colNames = F)
f1$X2 <- paste('d1$X5 <-f1("',f1$X1,'")', sep='')
f1$X3 <- paste('d1$X6 <-f2("',f1$X1,'")', sep='')

and I obtain something like
   X1               X2                X3
1 AAA d1$X5 <-f1("AAA") d1$X6 <-f2("AAA")
2 AAa d1$X5 <-f1("AAa") d1$X6 <-f2("AAs")
3 ABa d1$X5 <-f1("ABa") d1$X6 <-f2("ABs")

How can I integrate the above in the DYNAMIC PART of my script above? I am
sure there is a pretty simple solution but I seem not to get around to it.

Thanks,

Luca

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Mr. Luca Meyer
www.lucameyer.com