1

I have a function which takes multiple csv files and processes them into an excel file.

#review.R

review <- function(... ,savename) {
 somecodes
}

and I have these files in my folder:

fileA.csv
fileB.csv
fileC.csv
fileD.csv
...

and this is how I run it:

review("fileA","fileB","fileC","fileD", savename="analysis")

And then it processes and outputs "analysis.xlsx"

I have no problem running it in RStudio, but I really would like to run my script in cmd line like this:

rscript.exe f_wrapper.r "fileA" "fileB" "fileC" "fileD" savename="analysis"

This is my f_wrapper.R

#f_wrapper.R
#this script doesn't work at all

args <- commandArgs(TRUE)
obj <- list(...)


source("my_R_folder/review.R")

review(obj)

I googled all over but all I could find was passing fixed arguments like a,b,c but I am trying to pass a,b,c,d,e .... and more arguments to my function.

Please help.

Minus C
  • 53
  • 1
  • 5
  • Put the args in a list, and use `do.call(review, thelist)`. – user2554330 Sep 06 '20 at 11:57
  • You'll need to parse `args` to make the difference between `savename` and the other arguments. Did you have a look at : https://stackoverflow.com/questions/3433603/parsing-command-line-arguments-in-r-scripts ? – Waldi Sep 06 '20 at 13:41

0 Answers0