Hi,
Is it possible to provide a custom function to type argument in add_argument?
For example, something similar to:
non_empty_existing_file <- function(inputfile) {
if(!file.exists(inputfile)) {
stop("Non existing input path:", inputfile)
} else if(file.info(inputfile)$size == 0) { # check empty
stop("Input file is empty:", inputfile)
}
return(inputfile)
}
parser = ArgumentParser(prog='PROG')
parser$add_argument('input_file', type=non_empty_existing_file(), help="Input file.")
args <- parser$parse_args(commandArgs(TRUE))
Currently, this example does not work, because input_file value is not passed to non_empty_existing_file.
I haven't seen any examples using custom types and it would be really useful.
If it is supported already, could you add some examples to the documentation?
Thanks in advance.
Ellen
Hi,
Is it possible to provide a custom function to
typeargument inadd_argument?For example, something similar to:
Currently, this example does not work, because
input_filevalue is not passed tonon_empty_existing_file.I haven't seen any examples using custom types and it would be really useful.
If it is supported already, could you add some examples to the documentation?
Thanks in advance.
Ellen