trevorld / r-argparse

command-line optional and positional argument parser
GNU General Public License v2.0
103 stars 11 forks source link

add_argument function takes "." as atomic vector #22

Closed krisspnet closed 6 years ago

krisspnet commented 6 years ago

Hi,

Argparse on R would be a very convenient tool for me, however I have the following issue when I try to add an argument.

R> parser <- ArgumentParser(description='Processing arguments') R> parser$add_argument('x') Error in .$python_code : $ operator is invalid for atomic vectors

Looking at the add_argument function, the issue doesn't seem obvious to me, can you help?

R> parser$add_argument function (., ...) { .$python_code <- c(.$python_code, sprintf("parser.add_argument(%s)", convert_..._to_arguments("add_argument", ...))) return(invisible(NULL)) } <environment: 0x2e7fb58>

Thanks!

krisspnet commented 6 years ago

This seems to work only with the version 1.0.7, not the latest

trevorld commented 6 years ago

Thanks for the bug report. Not reproducible on my end or on Travis-CI using either the 'oldrel', 'release', or 'development' versions of R.

1) Do you have a fairly old version of R (in particular pre 3.3.2 which is my version of R which is even older than 3.3.3 which is the 'oldrel' tested by Travis CI and CRAN) and if so which one? 2) Does the error go away if you call library("proto") before library("argparse")?

I suspect your error is because I recently moved the proto package from the Depends field to the Imports field in the DESCRIPTION file and I think there is a bug in old versions of R where proto doesn't import correctly as it should. I'm not sure which version exactly it was fixed but I guess I should add at least an R (>= 3.3.2) dependency in my DESCRIPTION since it seems to work for R versions at least that new.

trevorld commented 6 years ago

I was able to reproduce your bug if I downgraded the dependency proto from version 1.0.0 (released 2016-10-29) to the previous version (released 2012-12-22).

You should be able to get the newest version of argparse working if you upgrade your version of proto.

update.packages(oldPkgs = "proto")

Meanwhile I'll update the DESCRIPTION file to require proto (>= 1.0.0).

trevorld commented 6 years ago

I've updated the DESCRIPTION file to explicitly require proto (>= 1.0.0).