jhylands
jhylands

Reputation: 1014

Is it possible to pass an entire list as a command line argument in R

I'm trying to pass a list of elements as an argument to an R script.

R -f myscript.R --people "James" "John" "Emily" "Anna"

I'm trying to make use of the optparse library to try and do the same as this answer which uses the argparser in python.

Upvotes: 1

Views: 763

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84529

I think optparse accepts only one argument for each "flag". I would use a comma-separated list:

R -f myscript.R --people James,John,Emily,Anna

And in your script you get the character string "James,John,Emily,Anna" that you can split with strsplit to get the vector of names.

Upvotes: 2

Related Questions