trevorld / r-argparse

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

Add 'parse_known_args()' #34

Closed WaterKnight1998 closed 2 years ago

WaterKnight1998 commented 2 years ago

Hi,

When calling parser$parse_args() I am getting an unrecognized arguments error. In python there is a function called parse_known_args that doesn't look present on your implementation.

How can I solve this issue with your library?

trevorld commented 2 years ago

Please provide a minimal, reproducible example. Thanks!

WaterKnight1998 commented 2 years ago

Please provide a minimal, reproducible example. Thanks!

test.R

library("argparse")

parser <- ArgumentParser(description='')
parser$add_argument("-x", dest = "x", type = "character", default = "testValue")

opt <- parser$parse_args()

If I execute this scrip as follows: Rscript test.R -x value1 -y value

I get at error telling me that -y parameter is unknown.

As suggested in StackOverflow to avoid this error you must use args, unknown = parser.parse_known_args(). More info in this link: https://stackoverflow.com/a/12818237

Howevere, this function is not implemented in your R wrapper.