MyNixOS website logo
Description

Command-Line Argument Parser.

Cross-platform command-line argument parser written purely in R with no external dependencies. It is useful with the Rscript front-end and facilitates turning an R script into an executable script.

README

argparser is a cross-platform command-line argument parser for R, written in R, with no external dependencies. This package is useful with the Rscript front-end and facilitates turning an R script into an executable script.

History

v0.7

  • Missing argument values are now handled correctly

v0.6

Incompatibility: values of numeric and integer arguments are now checked for validity due to feature request (issue #16)

v0.5.1

  • Negative numbers can now be parsed correctly as argument values
  • Help message printing is prettier
  • Concatenated short-form flags are now split into individual flags

v0.4 Simplify argument names

Incompatibility: - in argument names are substitute by _

v0.3 Added support for multi-valued arguments

v0.2 Function names change

Incompatibility: . in function names are replaced with _

v0.1 Initial release

Dependencies

  • R (>= 3.0)
  • roxygen2 (>= 4.0, for building only)

Build

Clone the repository, build the documentation with roxygen2, then install.

$ git clone https://bitbucket.org/djhshih/argparser.git
$ cd argparser
$ R

R> library(roxygen2)
R> roxygenize()
R> quit()

$ R CMD INSTALL .

Usage

Create a R script (e.g. round.R) with a shebang line (Linux only).

Import the argparser library, create a parser, populate the parser with arguments and parse the command line arguments.

#!/usr/bin/env Rscript

library(argparser, quietly=TRUE)

# Create a parser
p <- arg_parser("Round a floating point number")

# Add command line arguments
p <- add_argument(p, "number", help="number to round", type="numeric")
p <- add_argument(p, "--digits", help="number of decimal places", default=0)

# Parse the command line arguments
argv <- parse_args(p)

# Do work based on the passed arguments
cat( round(argv$number, argv$digits), "\n")

Then, set the R script as executable and execute (Linux only).

$ chmod +x round.R

# Print the help message
$ ./round.R -h

Alternatively, run the script using Rscript (Linux or Windows).

$ Rscript round.R 3.141
# 3

$ Rscript round.R 3.141 -d 2
# 3.14

For R help, see ?argparser.

Metadata

Version

0.7.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows