This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I parse arguments from a config file to create a command line menu in R ?

I have a script called config.r and it is like that :

# General info
exp_name = 'Exp_1'
file_in = '/dim/data/SRR23445.fastq'
# Quality 
trim_q = 10
trim_str = 3 
# Mapping
multimaps = 3

I would like instead of changing the config file everytime to have an argument menu for each of those parameters. The user would me able to specify the name of the output file the parameters for mapping for quality etc How can i do this in R?

r arguments script

may be snakemake can do this. It supports passing config files to R.

2 answers

It requires python externally I believe, but the extremely good Argparse library has been ported over to R, it does a lot of the heavy lifting in creating the interfaces for you:

https://cran.r-project.org/web/packages/argparse/index.html

There are many ways, both the janky, and the robust, to read in a config file of arguments that Argparse can use. See these links for more:

Here's an example script of mine if you want to see how it's used. The output of Rscript AverageMatrices.R --help looks like (like you might expect from any commandline tool):

usage: AverageMatrices.R [-h] -i INFILES [INFILES ...] [-s SEPARATOR] -o
                         OUTFILE

optional arguments:
  -h, --help            show this help message and exit
  -i INFILES [INFILES ...], --infiles INFILES [INFILES ...]
                        All the matrices to average.
  -s SEPARATOR, --separator SEPARATOR
                        The field separator for the input matrices (they
                        should all match). [Def = "tab"].
  -o OUTFILE, --outfile OUTFILE
                        Output file to store the averaged matrix in.

Script:

I would like to have a menu in which either you can use default config for the default values, or provide the user with the option to make a user config . More specific:

a. Necessary args: Input file, output directory

b.If user-config is passed as arg, use rest of values from there

c.If no user-config is passed as arg, use the default-config for values

d.If any variable is passed as arg, overwrite all the above for it

I dont want to do it in Bash. I want to do it in R. I want to be able to run for example config.r -exp EXP1 -path /dim/data/SRR23445.fast -q 10 - str 3 -m 3 etc and this will overwrite the existing config file and then this config file will be used for my pipeline with source

Log in to answer this question.