readComplexArgs: Read Complex Args

View source: R/readComplexArgs.R

readComplexArgsR Documentation

Read Complex Args

Description

Split complex command-line arguments into their component pieces

Usage

readComplexArgs(
  arg_v,
  colSep_v = ";",
  varValSep_v = "\\.",
  valSep_v = ",",
  simplify_v = T
)

Arguments

arg_v

vector containing the complex argument. See details for more info

colSep_v

character. default is ";". Whatever character separates different columns in arg_v. See details

valSep_v

character. default is ",'. Whatever character separates factor levels in arg_v. See details

simplify_v

logical. default is TRUE. TO DO - should I simplify the empty list to a vector?

varvalSep_v

character. default is "\." Whatever character separates a column name from its factor levels in arg_v. See details

Details

When running a command-line Rscript, sometimes you need to pass complex arguments like comma-separated lists of variables. You can't have any spaces in command-line args, so have to provide the argument all together in one string and split it inside R.

The format for a complex argument is: colName1.val1,val2,val3,...;colName2.val2,val2,...;colNameN... So first there is a semi-colon separated vector of column specifications. The column specification begins with the column name, optionally followed by factor levels for that column.

Each column can either have factor levels or not, they don't all have to be one or the other.

If you don't have factor levels, the argument is simply: colName1;colName2;colName3;... In this case, ";" and ',' will be treated the same for backwards compatibility.

Note that colSep_v (;), varValSep_v (.), and valSep_v (,) can all be specified.

Value

Returns a list of length = number of elements split by colSep_v, with those elements as the names. If factors provided, lists will have values in factor order. If not provided, lists will be empty with names only.


weshorton/wrh.rUtils documentation built on Oct. 28, 2024, 7:24 a.m.