Jonathan Greenberg
2009-Nov-02 18:56 UTC
[R] "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
--
Jonathan A. Greenberg, PhD
Postdoctoral Scholar
Center for Spatial Technologies and Remote Sensing (CSTARS)
University of California, Davis
One Shields Avenue
The Barn, Room 250N
Davis, CA 95616
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307
hadley wickham
2009-Nov-02 19:02 UTC
[R] "Safe" way to automatically install required packages...
If you package "depends" on another package, it will be automatically installed. Hadley On Mon, Nov 2, 2009 at 12:56 PM, 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 > > -- > > Jonathan A. Greenberg, PhD > Postdoctoral Scholar > Center for Spatial Technologies and Remote Sensing (CSTARS) > University of California, Davis > One Shields Avenue > The Barn, Room 250N > Davis, CA 95616 > Phone: 415-763-5476 > AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- http://had.co.nz/
Charlie Sharpsteen
2009-Nov-02 20:06 UTC
[R] "Safe" way to automatically install required packages...
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? > --jPlace 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