Learn R Programming

Xmisc (version 0.2.1)

ArgumentParser-class: Parser for command-line options and arguments

Description

Parser for command-line options and arguments

Arguments

Fields

cmdargs
list
exeargs
character
args
list
types
list
defaults
list
helps
list
usage
character
description
character

Methods

add_argument(name, ..., type, default, required = FALSE, help = "", dest, action)
Add an argument.
add_description(x)
Add a description.
add_usage(x)
Add a usage.
make_help()
Make and display `usage'.

Examples

Run this code
## Test
require(Xmisc)
parser <- ArgumentParser$new()
parser$add_argument('--a_str',type='character')
parser$add_argument('--b_num',type='numeric',default='0')
a_str
## character(0)
b_num
## [1] 0
message(parser$get_help())
## Usage:
##     /bin/exec/R ...
## Description:
## Options:
##     a_str character
##     b_num numeric   [ 0 ]

## Not run: 
# ## Test from a command line
# R -q -e "
# require(methods);require(Xmisc);
# parser <- ArgumentParser\$new();
# parser\$add_argument('--a_str',type='character');
# parser\$add_argument('--b_num',type='numeric',default='0');
# printme(a_str);printme(b_num);parser\$get_help();
# " --args --a_str='Hello World!' --b_num=1
# ## Loading required package: Xmisc
# ## ## a_str ##
# ## [1] "Hello World!"
# ## ## b_num ##
# ## [1] 1
# ## ...
# ## End(Not run)

Run the code above in your browser using DataLab