Reputation: 211
in R,the pdf function can save graph in c:/test
:
pdf("c:/test")
I want to make a variable substitue pdf ,how can i make it run ?
str<-"pdf"
str("c:/test")
Upvotes: 0
Views: 103
Reputation: 77096
s = "pdf" ; do.call(s, list("c:/test"))
or in two steps,
cl <- call(s, "c:/test")
eval(cl)
Upvotes: 2
Reputation: 81693
You can extract the function specified by the name in str
with match.fun
:
match.fun(str)("c:/test")
By the way: It is not a good idea to name an object str
since this is the name of a basic function in R.
Upvotes: 1