[R] "Safe" way to automatically install required packages...

Charlie Sharpsteen chuck at sharpsteen.net
Mon Nov 2 21:06:28 CET 2009


On Mon, Nov 2, 2009 at 10:56 AM, Jonathan Greenberg
<greenberg at ucdavis.edu> wrote:
> R-helpers:
>
>   I'm working on an r-package that I want to make as easy-to-use as possible
> for a novice R-user, which includes automatically installing required
> packages.   I, myself, am a novice R-packager, so the solution I came up
> with was to embed:
>
> print("Loading required packages...")
> if (!require("reshape")) { install.packages("reshape") }
> if (!require("reshape")) {
>   print("Could not install package 'reshape', please contact your
> sysadmin.")
>   return()
> }
>
>   in the code proper, and put together the package using package.skeleton()
> and R CMD build.
>
>   I'm guessing there's a better way to do this -- any suggestions?
> --j

Place the dependencies of your package in a comma-seperated list in the

  depends:

field of the DESCRIPTION file. When a user runs install.packages(
'yourPackage', dependencies = T ), R will take care of downloading and
installing the dependencies

-Charlie




More information about the R-help mailing list