Skip to content
Prev 198871 / 398506 Next

"Safe" way to automatically install required packages...

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