0

I'm attempting to debug a script "normalize.R" that uses argparse in R and the way I came up with is to make a script that sources the other script so I can debug.

I attempted the method of overwriting the commandArgs() function to return a list, but it seems that argparse doesn't use that function. Printing commandArgs() shows the expected arguments but printing output of argparse$parse_args() does not

commandArgs <- function(trailingOnly=True){
  return(c("--args", "--arg1", "foo", "--arg2", "fey"))
}

source("./normalize.R")

Is there a way to pass arguments to a script that uses argparse from R instead of the command line?

Also better workflows for debugging are also appreciated, but my curiosity is now peaked about how parse_args() works

Phil
  • 5,491
  • 3
  • 26
  • 61
  • Please include an example `normalize.R` script so that possible solutions can be tested and verified. Include the specific `library()` calls for non base R packages you are using and show exactly how the script is parsing arguments. Rather than `source()`, call your script with something like`system2("Rscript", c("./normalize.R", "--args", "--arg1", "foo", "--arg2", "fey"))` – MrFlick Aug 17 '21 at 16:52

0 Answers0