0

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")

3 Answers 3

2

get() does this:

get(str)("c:/test")
Sign up to request clarification or add additional context in comments.

Comments

2

s = "pdf" ; do.call(s, list("c:/test"))

or in two steps,

cl <- call(s, "c:/test")
eval(cl)

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.