Reputation: 457
I am working within a small group of mostly non-technical users and would like to distribute an R script within the group. This uses 'RScript' in the shebang line, takes some command line arguments and produces a graphics file and some text as output.
I am wondering if there are ways to ensure that any external packages that the script uses (even something like optparse for parsing arguments) is available to the user. I expect that everyone in the group will be able to invoke the program from the command line by following instructions but asking people to start R and download and install dependencies might be too much. I've used py2exe or py2app for similar situations in Python, but I am wondering if there are equivalent ways or at least best practices for distributing R scripts.
Upvotes: 3
Views: 409
Reputation: 94172
Dirk's given you the best practice solution (packages with dependencies) but the next-best-practice solution is probably to use require(foo) and test if the package is there, and then get it if not. Something like:
if(require(foo)){
# foo loaded okay
cat("we got foo\n")
}else{
cat("uh oh, no foo. let's get it\n")
install.packages("foo")
}
you might want to specify a CRAN repo in install.packages so the user isn't interrogated, and also to use some options on require to stop warnings.
Upvotes: 7
Reputation: 368181
Create a package, declare the dependencies as Depends: in DESCRIPTION. That works, and is tested widely across OSs.
You can then also place the package in a local repository, making updates easier and possibly even automatic. I once wrote a company-internal package which in its own startup code checked if a newer version was available on the local repository.
Upvotes: 10