argparser/0000755000176200001440000000000014603432222012236 5ustar liggesusersargparser/NAMESPACE0000644000176200001440000000033714311037556013467 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method(print,arg.parser) export(add.argument) export(add_argument) export(arg.parser) export(arg_parser) export(include) export(parse.args) export(parse_args) import(methods) argparser/demo/0000755000176200001440000000000014603267053013172 5ustar liggesusersargparser/demo/sum2.R0000754000176200001440000000104514311037545014202 0ustar liggesusers#!/usr/bin/env Rscript library(argparser, quietly=TRUE) # Create a parser p <- arg_parser("Calculate the sum of two numbers") # Add command line arguments # Note: The values for the numbers argument have to provided as a comma # separated string, since we are specifying a position argument here. p <- add_argument(p, "numbers", help="comma separated list of two numbers to add", nargs=2, type="numeric") # Parse the command line arguments argv <- parse_args(p) # Do work based on the passed arguments cat( sum(argv$numbers), "\n") argparser/demo/sum.R0000754000176200001440000000144314426374403014126 0ustar liggesusers#!/usr/bin/env Rscript library(argparser, quietly=TRUE) # Create a parser p <- arg_parser("Calculate the sum of a set of numbers") # Add command line arguments p <- add_argument(p, "--numbers", help="numbers to add", nargs=Inf, type="numeric") p <- add_argument(p, "--logsumexp", help="calculate sum in exponentiated space instead", flag=TRUE) p <- add_argument(p, "--subset", help="start and end (1-based) indices of subset of numbers to add", type="integer", default=c(1, Inf)); # Parse the command line arguments argv <- parse_args(p) # Do work based on the passed arguments idx <- argv$subset; if (is.infinite(idx[2])) { idx[2] <- length(argv$numbers); } if (argv$logsumexp) { fun <- function(x) log(sum(exp(x))); } else { fun <- sum } cat( fun(argv$numbers[idx[1]:idx[2]]), "\n") argparser/demo/round.R0000754000176200001440000000070314311037545014443 0ustar liggesusers#!/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") argparser/demo/underscore.R0000754000176200001440000000040514426373661015475 0ustar liggesusers#!/usr/bin/env Rscript library(argparser) ap <- arg_parser("test") ap <- add_argument(ap, "--n-cores", default=1L, help="number of cores") ap <- add_argument(ap, "--num-proc", default=1L, help="number of processes") args <- parse_args(ap) print(names(args)) argparser/demo/round-magrittr.R0000754000176200001440000000114314311037545016271 0ustar liggesusers#!/usr/bin/env Rscript library(magrittr, quietly=TRUE) library(argparser, quietly=TRUE) # Create a parser and add arguments, and parse the command line arguments # All steps are chained together, courtesy of magrittr p <- arg_parser("Round a floating point number") %>% add_argument("number", help="number to round", type="numeric") %>% add_argument("--digits", help="number of decimal places", default=0) # Parse the command line arguments # This step is kept separate to simply error message argv <- parse_args(p) # Do work based on the passed arguments cat( round(argv$number, argv$digits), "\n") argparser/demo/prime.R0000754000176200001440000000121114311037545014423 0ustar liggesusers#!/usr/bin/env Rscript library(argparser, quietly=TRUE) # Create a parser p <- arg_parser("Check if positive integer is prime") # Add command line arguments p <- add_argument(p, "--number", help="numbers to check", type="integer") # Parse the command line arguments argv <- parse_args(p) n <- argv$number; if (is.na(n)) { stop("No number specified") } if (n == 1) { prime <- FALSE; } else if (n == 2) { prime <- TRUE; } else if (n > 2) { prime <- TRUE; # inefficient check for (i in 2:(n-1)) { if (n %% i == 0) { prime <- FALSE; break; } } } if (prime) { message(n, " is prime.") } else { message(n, " is not prime.") } argparser/demo/00Index0000644000176200001440000000060214603267053014322 0ustar liggesusersprime demo command-line program prime checking round demo command-line program for rounding floating point numbers round-magrittr demo command-line program with magrittr integration to simplify code sum demo command-line program for summing a set numbers sum2 demo command-line program for summing two numbers underscore demo command-line program with argument names containing hyphens argparser/README.md0000644000176200001440000000446714311037545013535 0ustar liggesusers# 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`. argparser/man/0000755000176200001440000000000014603266642013024 5ustar liggesusersargparser/man/arg.parser.Rd0000644000176200001440000000064614311037556015361 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/deprecated.R \name{arg.parser} \alias{arg.parser} \title{Create an argument parser.} \usage{ arg.parser(description, name = NULL) } \arguments{ \item{description}{description of the program} \item{name}{name of the program} } \value{ a new \code{arg.parser} object } \description{ This function is deprecated. Use \code{arg_parser} instead. } argparser/man/include.Rd0000644000176200001440000000055614311037556014740 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/include.R \name{include} \alias{include} \title{Include R script file} \usage{ include(file) } \arguments{ \item{file}{name} } \description{ Include R script with behaviour similar to C++ \code{#include "header.h"}, by searching in the directory where the current script file resides. } argparser/man/print.arg.parser.Rd0000644000176200001440000000077214311037556016514 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/argparser.R \name{print.arg.parser} \alias{print.arg.parser} \title{Print the help message for an arg.parser.} \usage{ \method{print}{arg.parser}(x, ...) } \arguments{ \item{x}{an \code{arg.parser} object} \item{...}{unused arguments} } \description{ This function prints the help message. } \details{ At the command line, we would use the \code{--help} or \code{-help} flag to print the help message: \code{$ script --help} } argparser/man/arg_parser.Rd0000644000176200001440000000145414311037556015440 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/argparser.R \name{arg_parser} \alias{arg_parser} \title{Create an argument parser.} \usage{ arg_parser(description, name = NULL, hide.opts = FALSE) } \arguments{ \item{description}{description of the program} \item{name}{name of the program} \item{hide.opts}{hide the \code{--opts} argument} } \value{ a new \code{arg.parser} object } \description{ This function creates an \code{arg.parser} object. It infers the program name from the file name of the invoked script. } \details{ The argument parser will be created by default with two arguments: \code{--help} and \code{--opts}. The latter argument can be used for loading a list of argument values that are saved in a RDS file. } \examples{ p <- arg_parser("A test program") } argparser/man/add.argument.Rd0000644000176200001440000000227014311037556015661 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/deprecated.R \name{add.argument} \alias{add.argument} \title{Add an argument to a parser.} \usage{ add.argument( parser, arg, help, default = NULL, type = NULL, flag = NULL, short = NULL ) } \arguments{ \item{parser}{an \code{arg.parser} object} \item{arg}{argument name (use no prefix for positional arguments, \code{--} or \code{-} prefix for optional arguments or flags)} \item{help}{help description for the argument} \item{default}{default value for the argument [default: NA]} \item{type}{variable type of the argument (which can be inferred from \code{default}), assumed to be \code{character} otherwise} \item{flag}{whether argument is a flag (and does not consume a value) [default: FALSE]} \item{short}{short-form for flags and positional arguments; short-forms can be assigned automatically based on the first character of the argument name, unless a conflict arises with an existing short-form; to avoid conflicts, add the argument as early as possible} } \value{ an \code{arg.parser} object with the argument added } \description{ This function is deprecated. Use \code{add_argument} instead. } argparser/man/spaces.Rd0000644000176200001440000000044014311037556014563 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/argparser.R \name{spaces} \alias{spaces} \title{Space string.} \usage{ spaces(n) } \arguments{ \item{n}{number of spaces} } \value{ a character string containing \code{n} spaces } \description{ Space string. } argparser/man/parse.args.Rd0000644000176200001440000000100014311037556015343 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/deprecated.R \name{parse.args} \alias{parse.args} \title{Parse arguments with a parser.} \usage{ parse.args(parser, argv = commandArgs(trailingOnly = TRUE)) } \arguments{ \item{parser}{an \code{arg.parser} object} \item{argv}{a character vector to parse (arguments and values should already be split by whitespace)} } \value{ a list with argument values } \description{ This function is deprecated. Use \code{parse_args} instead. } argparser/man/add_argument.Rd0000644000176200001440000000666314311037556015754 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/argparser.R \name{add_argument} \alias{add_argument} \title{Add an argument to a parser.} \usage{ add_argument( parser, arg, help, default = NULL, type = NULL, nargs = NULL, flag = NULL, short = NULL ) } \arguments{ \item{parser}{an \code{arg.parser} object} \item{arg}{argument name (use no prefix for positional arguments, \code{--} or \code{-} prefix for optional arguments or flags)} \item{help}{help description for the argument} \item{default}{default value for the argument [default: NA]} \item{type}{variable type of the argument (which can be inferred from \code{default}); assumed to be \code{character} otherwise. See details for more information.} \item{nargs}{number of argument values (which can be inferred from \code{default}); set to \code{Inf} for an indefinite number; an optional argument with an indefinite number of values may need to be followed by another optional argument or flag (e.g. \code{--}) to separate the indefinite optional argument from possible position arguments} \item{flag}{whether argument is a flag (and does not consume a value) [default: FALSE]; during argument parsing, a flag argument is FALSE by default if it is not set} \item{short}{short-form for flags and positional arguments; short-forms can be assigned automatically based on the first character of the argument name, unless a conflict arises with an existing short-form; to avoid conflicts, add the argument as early as possible} } \value{ an \code{arg.parser} object with the argument added } \description{ This function adds an argument to an \code{arg.parser} object and returns the modified object. } \details{ This function supports multiple arguments in a vector. To ensure that the argument variable type is set correctly, either specify \code{type} directly or supply \code{default} argument values as a list. Custom types are supported by defining a new class and a S4 method for \code{coerce}, see the examples section. } \note{ Dashes \code{-} that occur in the stem of the argument names (e.g. --argument-name) will be converted to underscores \code{_} (e.g. argument_name) in the name of the corresponding variable. } \examples{ p <- arg_parser("A text file modifying program") # Add a positional argument p <- add_argument(p, "input", help="input file") # Add an optional argument p <- add_argument(p, "--output", help="output file", default="output.txt") # Add a flag p <- add_argument(p, "--append", help="append to file", flag=TRUE) # Add multiple arguments together p <- add_argument(p, c("ref", "--date", "--sort"), help = c("reference file", "date stamp to use", "sort lines"), flag = c(FALSE, FALSE, TRUE)) # Print the help message print(p) # Example of custom type, using the example from pythons argparse setClass("perfectSquare") setMethod("coerce", c(from = "ANY", to = "perfectSquare"), function(from, to) { from <- as.numeric(from) if (!all.equal(from, as.integer(from))) { stop("Type error: ", from, " is not an integer!") } sqt <- sqrt(from) if (sqt != as.integer(sqt)) { stop("Type error: ", from, " is not a perfect square!") } from } ) p2 <- arg_parser("Perfect square checker") p2 <- add_argument(p2, arg = c("--perfect-square"), help = "A perfect square integer", type = "perfectSquare") parse_args(p2, c("--perfect-square", 144)) } argparser/man/show_arg_labels.Rd0000644000176200001440000000077514311037556016453 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/argparser.R \name{show_arg_labels} \alias{show_arg_labels} \title{Extract label and help strings from parser.} \usage{ show_arg_labels(parser) } \arguments{ \item{parser}{\code{arg.parser} object} } \value{ a list containing a \code{reg.args}, \code{flags}, and \code{opt.args} list, which each containing a \code{label} string and a \code{help} string } \description{ Extract label and help strings from parser. } argparser/man/parse_args.Rd0000644000176200001440000000250614426404016015434 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/argparser.R \name{parse_args} \alias{parse_args} \title{Parse arguments with a parser.} \usage{ parse_args(parser, argv = NULL) } \arguments{ \item{parser}{an \code{arg.parser} object} \item{argv}{a character vector to parse (arguments and values should already be split by whitespace); if \code{NULL}, values will be obtained from \code{argv} if \code{argv} exists in the global scope, or from \code{commandArgs(trailingOnly=TRUE)}.} } \value{ a list with argument values } \description{ This function uses an \code{arg.parser} object to parse command line arguments or a character vector. } \examples{ p <- arg_parser('pi') p <- add_argument(p, "--digits", help="number of significant digits to print", default=7) \dontrun{ # If arguments are passed from the command line, # then we would use the following: argv <- parse_args(p) } # For testing purposes, we can pass a character vector: argv <- parse_args(p, c("-d", "30")) # Now, the script runs based on the passed arguments digits <- if (argv$digits > 22) 22 else argv$digits print(pi, digits=digits) \dontrun{ # We can also save an argument list for later use saveRDS(argv, "arguments.rds") # To use the saved arguments, use the --opts argument at the command line #$ ./script.R --opts arguments.rds } } argparser/man/argparser-package.Rd0000644000176200001440000000163414603272161016667 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/argparser-package.R \docType{package} \name{argparser-package} \alias{argparser} \alias{argparser-package} \title{Command-line argument parser} \description{ \code{argparser} provides functions for parsing command-line arguments. } \details{ To use the parser, \enumerate{ \item create an \code{arg.parser} object with \code{\link{arg_parser}}; \item add arguments to the parser with \code{\link{add_argument}}; \item call \code{\link{parse_args}} to parse the command line arguments. } To execute the script, invoke \code{Rscript}. Alternatively on Linux, insert a shebang on the first line (\code{#!/usr/bin/env Rscript}) and \code{chmod +x} the script, } \seealso{ Useful links: \itemize{ \item \url{https://bitbucket.org/djhshih/argparser} \item Report bugs at \url{https://bitbucket.org/djhshih/argparser/issues} } } \keyword{internal} argparser/DESCRIPTION0000644000176200001440000000133514603432222013746 0ustar liggesusersPackage: argparser Type: Package Title: Command-Line Argument Parser Version: 0.7.2 Author: David J. H. Shih Maintainer: David J. H. Shih Description: 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. URL: https://bitbucket.org/djhshih/argparser BugReports: https://bitbucket.org/djhshih/argparser/issues Depends: methods Suggests: testthat (>= 3.0.0) License: GPL (>= 3) RoxygenNote: 7.2.3 Encoding: UTF-8 Config/testthat/edition: 3 NeedsCompilation: no Packaged: 2024-04-03 15:42:34 UTC; davids Repository: CRAN Date/Publication: 2024-04-04 05:03:14 UTC argparser/tests/0000755000176200001440000000000014311037545013405 5ustar liggesusersargparser/tests/testthat/0000755000176200001440000000000014426404023015241 5ustar liggesusersargparser/tests/testthat/test_missing.R0000644000176200001440000000227314311037545020104 0ustar liggesusersp <- arg_parser("Test") p <- add_argument(p, "--arg1", help = "arg1", type = "numeric") p <- add_argument(p, "--arg2", help = "arg2", type = "integer") test_that("numerics are parsed correctly", { argv <- parse_args(p) expect_true(is.na(argv$arg1)) expect_true(is.na(argv$arg2)) expect_equal(parse_args(p, c("--arg1", "1e-9"))$arg1, 1e-9) expect_equal(parse_args(p, c("--arg1", "1.5e9"))$arg1, 1.5e9) expect_equal(parse_args(p, c("--arg1", "-1234.5"))$arg1, -1234.5) expect_error(parse_args(p, c("--arg1", "A"))) }) test_that("integers are parsed correctly", { expect_equal(parse_args(p, c("--arg2", "100"))$arg2, 100) expect_equal(parse_args(p, c("--arg2", "-99"))$arg2, -99) expect_error(parse_args(p, c("--arg2", "A"))) expect_error(parse_args(p, c("--arg2", "4.3"))) expect_error(parse_args(p, c("--arg2", "1.0e-9"))) }) test_that("missing arguments are accepted", { argv <- parse_args(p, c("--arg1", "1.5", "--arg2", "2")) expect_equal(argv$arg1, 1.5) expect_equal(argv$arg2, 2) argv <- parse_args(p, c("--arg1", "3")) expect_equal(argv$arg1, 3) expect_true(is.na(argv$arg2)) argv <- parse_args(p, c("--arg2", "4")) expect_equal(argv$arg2, 4) expect_true(is.na(argv$arg1)) }) argparser/tests/testthat/test_s4.R0000644000176200001440000000151714311037545016761 0ustar liggesusers# Define greeting type with a defined set of valid values setClass("greeting_type") setMethod("coerce", c(from = "ANY", to = "greeting_type"), function(from, to) { if(!from %in% c("hello", "hey", "hi")) { stop("Invalid type value for greeting_type: ", from) } from } ) p <- arg_parser("parser with S4 type") p <- add_argument(p, arg = "--number", help = "a number", type = "numeric") p <- add_argument(p, arg = "--greeting", help = "hello | hey | hi", type = "greeting_type") test_that("parser with S4 type parses correctly", { expect_equal( parse_args(p, c("--number", "4.2"))$number, 4.2 ) expect_match( parse_args(p, c("--greeting", "hello"))$greeting, "hello" ) expect_match( parse_args(p, c("--greeting", "hey"))$greeting, "hey" ) expect_error( parse_args(p, c("--greeting", "bye")) ) }) argparser/tests/testthat/test_vector.R0000644000176200001440000000106714311037545017735 0ustar liggesusersparser <- arg_parser("MWE") parser <- add_argument(parser, arg = c("--method", "--grid-length", "--problem-type"), help = c("arg1.","arg2.", "arg3."), default = list(NA, 400, "search"), type = c("character", "integer", "character"), nargs = c(1, 1, 1), flag = c(FALSE, FALSE, FALSE), short = c("-m", "-l", "-t") ) test_that("argument vector is parsed correctly", { argv <- parse_args(parser, c("-m", "novel", "-l", "400", "-t", "binary")) expect_equal(argv$method, "novel") expect_equal(argv$grid_length, 400) expect_equal(argv$problem_type, "binary") }) argparser/COPYING0000644000176200001440000000132014311037545013272 0ustar liggesusersargparser - R package for parsing command line arguments Copyright (C) 2015. David J. H. Shih argparser is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. argparser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with argparser. If not, see . argparser/R/0000755000176200001440000000000014603267655012457 5ustar liggesusersargparser/R/argparser-package.R0000644000176200001440000000115114603267655016157 0ustar liggesusers#' Command-line argument parser #' #' \code{argparser} provides functions for parsing command-line arguments. #' #' To use the parser, #' \enumerate{ #' \item create an \code{arg.parser} object with \code{\link{arg_parser}}; #' \item add arguments to the parser with \code{\link{add_argument}}; #' \item call \code{\link{parse_args}} to parse the command line arguments. #' } #' To execute the script, invoke \code{Rscript}. #' Alternatively on Linux, insert a shebang on the first line #' (\code{#!/usr/bin/env Rscript}) and \code{chmod +x} the script, #' #' @keywords internal "_PACKAGE" #' @import methods NULL argparser/R/zzz.R0000644000176200001440000000011014311037545013414 0ustar liggesusers.onLoad <- function(libname, pkgname) { options(argparser.delim=",") } argparser/R/deprecated.R0000644000176200001440000000443214311037545014672 0ustar liggesusers#' Create an argument parser. #' #' This function is deprecated. Use \code{arg_parser} instead. #' #' @param description description of the program #' @param name name of the program #' @return a new \code{arg.parser} object #' @export arg.parser <- function(description, name=NULL) { warning("Use arg_parser() instead: arg.parser() is deprecated and will be removed in argparser-0.4."); arg_parser(description, name) } #' Add an argument to a parser. #' #' This function is deprecated. Use \code{add_argument} instead. #' #' @param parser an \code{arg.parser} object #' @param arg argument name (use no prefix for positional arguments, #' \code{--} or \code{-} prefix for optional arguments or flags) #' @param help help description for the argument #' @param default default value for the argument [default: NA] #' @param type variable type of the argument (which can be inferred from #' \code{default}), assumed to be \code{character} otherwise #' @param flag whether argument is a flag (and does not consume a value) #' [default: FALSE] #' @param short short-form for flags and positional arguments; #' short-forms can be assigned automatically based on the first #' character of the argument name, unless a conflict arises with #' an existing short-form; to avoid conflicts, add the argument #' as early as possible #' @return an \code{arg.parser} object with the argument added #' @export add.argument <- function( parser, arg, help, default=NULL, type=NULL, flag=NULL, short=NULL ) { warning("Use add_argument() instead: add.argument() is deprecated and will be removed in argparser-0.4."); add_argument(parser, arg, help, default, type, flag, short) } #' Parse arguments with a parser. #' #' This function is deprecated. Use \code{parse_args} instead. #' #' @param parser an \code{arg.parser} object #' @param argv a character vector to parse (arguments and values should #' already be split by whitespace) #' @return a list with argument values #' @export parse.args <- function(parser, argv=commandArgs(trailingOnly=TRUE)) { warning("Use parse_args() instead: parse.args() is deprecated and will be removed in argparser-0.4."); parse_args(parser, argv) } argparser/R/argparser.R0000644000176200001440000005450214603266601014564 0ustar liggesusers#' Create an argument parser. #' #' This function creates an \code{arg.parser} object. It infers the program #' name from the file name of the invoked script. #' #' The argument parser will be created by default with two arguments: #' \code{--help} and \code{--opts}. The latter argument can be used for #' loading a list of argument values that are saved in a RDS file. #' #' @param description description of the program #' @param name name of the program #' @param hide.opts hide the \code{--opts} argument #' @return a new \code{arg.parser} object #' @export #' #' @examples #' p <- arg_parser("A test program") #' arg_parser <- function(description, name=NULL, hide.opts=FALSE) { # set default name if (is.null(name)) { # extract file name from command arguments, which will be empty # if the program is not invoked as a script prefix <- "--file="; name <- basename(sub(prefix, "", grep(paste(prefix, "(.+)", sep=""), commandArgs(), value=TRUE) )); } if (length(name) == 0) name <- "