2

The question is in the title. I'd like to do something like this :

myfunc<- pexp
plot(function(x) myfunc(x, 0.5))

I'd like to call several functions given as parameters in my script. I'd like to use a foreach instead of a bunch of if-then-else statement :

Suppose I call my script this way :

R --slave -f script.R --args plnorm pnorm 

I'd like to do something like this :

#only get parameters after --args
args<-commandArgs(trailingOnly=TRUE)
for i in args {
    plot(function(x) i(x,param1,param2))
}
0

1 Answer 1

6

Use get to retrieve an object given a character string containing its name. In this case, you can also use getFunction, the specific version to retrieve functions.

for f in args {
     f <- getFunction(f)
     plot(function(x) f(x, param1, param2))
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.