Here's how to use an R script like a Python script, relying on box. While there are reasons to use R, there are also two very bad parts of the R language, avoid them: (1) never use
source and (2) never use
library. These encourage patterns of code that are difficult to test or maintain. Using
source comes along with changing the working directory sometimes, which should also be avoided. I'll quote Jenny Bryan, who, among other things says
Have setwd() in your scripts? PLEASE STOP DOING THAT. ... I will come into your lab and SET YOUR COMPUTER ON FIRE.
She has also written a whole post on why
setwd() is, and I quote again, "so problematic and often associated with other awkward workflow problems".
There are three files here:
src/main/myscript.R: the main script, has functions that can be used elsewhere and also can be run standalone.