mystery argument

Issue #17 invalid
Ben Tupper created an issue

Hi,

I seem to pick up an extra argument ‘x', and I can’t identify where it comes from. Below is an example that uses pipes and another that does not (in case that matters). Out put of the script along with the session info follows.

library(magrittr, quietly=TRUE)
library(argparser, quietly=TRUE)

cat("\n\n with piping -------------------------------\n\n")

p <- argparser::arg_parser("This script parses it's arguments") %>%
  argparser::add_argument("input",
                          help = "positional argument - must be 0 < input <= 10") %>%
  argparser::add_argument("--no-foo",
                          help = "disable fooing?",
                          flag = TRUE) %>%
  argparser::add_argument("--bar",
                          help = "value of bar",
                          default = 7,
                          type = "numeric") %>%
  argparser::add_argument("--baz",
                          help = "baz suffix",
                          default = "cat",
                          type = "character")



print(p)


cat("\n\nwithout piping -------------------------------\n\n")

p <- argparser::arg_parser("This script parses it's arguments")

p <-   argparser::add_argument(p, "input",
                          help = "positional argument - must be 0 < input <= 10")
p <- argparser::add_argument(p, "--no-foo",
                          help = "disable fooing?",
                          flag = TRUE)
p <- argparser::add_argument(p, "--bar",
                          help = "value of bar",
                          default = 7,
                          type = "numeric")
p <- argparser::add_argument(p, "--baz",
                          help = "baz suffix",
                          default = "fish",
                          type = "character")

print(p)

cat("\n\nsessionInfo -------------------------------\n\n")
print(sessionInfo())

And the output on my platform…

btupper@ecocast ~ $ Rscript --vanilla example-argparse.R


 with piping -------------------------------

usage: example-argparse.R [--] [--help] [--no-foo] [--opts OPTS] [--bar
       BAR] [--baz BAZ] input

This script parses it's arguments

positional arguments:
  input         positional argument - must be 0 < input <= 10

flags:
  -h, --help    show this help message and exit
  -n, --no-foo  disable fooing?

optional arguments:
  -x, --opts    RDS file containing argument values
  -b, --bar     value of bar [default: 7]
  --baz         baz suffix [default: cat]



without piping -------------------------------

usage: example-argparse.R [--] [--help] [--no-foo] [--opts OPTS] [--bar
       BAR] [--baz BAZ] input

This script parses it's arguments

positional arguments:
  input         positional argument - must be 0 < input <= 10

flags:
  -h, --help    show this help message and exit
  -n, --no-foo  disable fooing?

optional arguments:
  -x, --opts    RDS file containing argument values
  -b, --bar     value of bar [default: 7]
  --baz         baz suffix [default: fish]



sessionInfo -------------------------------

R version 3.5.1 (2018-07-02)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] argparser_0.5.1 magrittr_1.5

loaded via a namespace (and not attached):
[1] compiler_3.5.1

I can’t noodle out where the optional argument ‘-x’ comes from.

Thanks!

Ben

Comments (4)

  1. David Shih repo owner

    This is an undocumented feature. It’s not a bug. You can see that the argument expects an RDS file (containing a list with values for the arguments).

  2. David Shih repo owner

    I forgot to mention that you can disable this behavior by calling arg_parser with hide.opts=TRUE. See ?arg_parser.

    I’ve added more explicit documentation to this function in dcd9adb.

  3. Log in to comment