Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can always write: Rscript --vanilla your_r_script.r (and #!/usr/bin/env Rscript --vanilla )

Command line arguments are available as:

args <- commandArgs(trailingOnly=TRUE)

And there are three getopt()-like packages: getopt, optparse, and argparse.



We've done that but someone used relative includes/require statements and everything broke. It's exceptionally annoying.


In this case you should probably use the "here" or the "rprojroot" packages (libraries in conventional R parlance). They both simplify the usage of relative paths inside a project/repository.

If you have a project root with the folders code, data, etc and are running a project on /path/root/code, you can then just call data_dir <- here::here("data") for the data folder, as the here package uses several always to find the root of a project (e.g., looking for a .git folder).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: