Passing multiple arguments via command line in R

前端 未结 5 1082
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 07:49

I am trying to pass multiple file path arguments via command line to an Rscript which can then be processed using an arguments parser. Ultimately I would want something like

5条回答
  •  广开言路
    2021-01-06 08:29

    After searching around, and avoiding to write a new package from the bottom up, I figured the best way to input multiple arguments using the package optparse is to separate input files by a character which is most likely illegal to be included in a file name (for example, a colon)

    Rscript test.R --inputfiles fileA.txt:fileB.txt:fileC.txt etc...
    

    File names can also have spaces in them as long as the spaces are escaped (optparse will take care of this)

    Rscript test.R --inputfiles file\ A.txt:file\ B.txt:fileC.txt etc...
    

    Ultimatley, it would be nice to have a package (possibly a modified version of optparse) that would support multiple arguments like mentioned in the question and below

    Rscript test.R --inputfiles fileA.txt fileB.txt fileC.txt
    

    One would think such trivial features would be implemented into a widely used package such as optparse

    Cheers

提交回复
热议问题