[R] How to integrate a dynamic code within a R script?

Luca Meyer lucam1968 at gmail.com
Sat Mar 24 22:03:42 CET 2018


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]]



More information about the R-help mailing list