1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/argparse.R
\name{ArgumentParser}
\alias{ArgumentParser}
\title{Create a command line parser}
\usage{
ArgumentParser(..., python_cmd = NULL)
}
\arguments{
\item{...}{Arguments cleaned and passed to Pythons \code{argparse.ArgumentParser()}}
\item{python_cmd}{Python executable for \code{argparse} to use.
Must have \code{argparse} and \code{json} modules (automatically bundled with Python 2.7 and 3.2+).
If you need Unicode argument support then you must use Python 3.0+.
Default will be to use \code{findpython} package to find suitable Python binary.}
}
\value{
\code{ArgumentParser()} returns a parser object which contains
an \code{add_argument()} function to add arguments to the parser,
a \code{parse_args()} function to parse command line arguments into
a list, a \code{print_help()} and a \code{print_usage()} function to print
usage information. See code examples, package vignette,
and corresponding python module for more information on how to use it.
}
\description{
\code{ArgumentParser()} creates a parser object that acts as
a wrapper to Python's \code{argparse} module
}
\examples{
if (argparse:::detects_python()) {
parser <- ArgumentParser(description='Process some integers')
parser$add_argument('integers', metavar='N', type = "integer", nargs='+',
help='an integer for the accumulator')
parser$add_argument('--sum', dest='accumulate', action='store_const',
const='sum', default='max',
help='sum the integers (default: find the max)')
parser$print_help()
# default args for ArgumentParser()$parse_args are commandArgs(TRUE)
# which is what you'd want for an Rscript but not for interactive use
args <- parser$parse_args(c("--sum", "1", "2", "3"))
accumulate_fn <- get(args$accumulate)
print(accumulate_fn(args$integers))
}
}
\references{
Python's \code{argparse} library, which this package is based on,
is described here: \url{https://docs.python.org/3/library/argparse.html}
}
|