In order to provide script arguments, first you would need to have an executable script. On Linux you can do that by providing the line
#!/usr/bin/Rscript
When you change file itself to executable, this line is going to tell your OS that script should be executed by Rscript(R interpreter).
Now, in order to get script arguments, you should provide the next line.
args <- commandArgs(trailingOnly= TRUE)
args is variable that is going to store your arguments. Usually first argument in script is executable environment of that script; by providing trailingOnly set to TRUE, we are going to avoid turning path to our executable environment to our first argument. With this optional argument, your args is going to contain only values you have provided with script calling.
At the end, if you want to use your script arguments, just call variable args with index number of value you want to use like:
message(args[1])
If you want to see how all of this works, check video tutorial below.
No comments:
Post a Comment