Consider this script in R that can be called from command line as ./add.R 1 2 to add two numbers:
Content of add.R (do chmod +x add.R to make it executable):
#!/usr/bin/env Rscript
'usage: add.r <a> <b>' -> doc
suppressMessages(library(docopt))
opts <- docopt(doc)
print(as.double(opts[["a"]]) + as.double(opts[["b"]]))
Is there any way to bundle add.R in an R package and have the installation process copy this script to PATH (or update PATH) and make it available for general use? That is, I should be able to do add.R 1 2 from anywhere.
In Python, setuptools lets you do this using scripts or console_scripts.