The objective is to have two simple ways to source some code, say func.R, containing a function. Calling R CMD BATCH func.R initializes the function and evaluat
R CMD BATCH func.R
Another option is:
#!/usr/bin/Rscript # runs only when script is run by itself if (sys.nframe() == 0){ # ... do main stuff }