Reputation: 19253
There is a R file and there is a function getInfo() in it. I want to run this function in that script file alone. Is that possible ? I know running the script command on the file and then running the function name will help. But then it will also run the rest of stuffs from the script file which i dont want. What is the best way out here
Upvotes: 0
Views: 344
Reputation: 60924
When you use source
on a script file, all the code in that file will be loaded into the R session currently active. Any code that is not in a function, will be executed. I see two options:
option
and retrieve its value in the file to be sourced using getOption
, making the execution of the non-function code dependend on this option. This does require you to always set this option before sourcing the file, in any project you use it in.I would go for option 1.
Upvotes: 1