Hello, when trying to write an R-file, which automatically installs and updates a given list of packages, I had two problems with install.packages() 1) install.packages("<package>") will install <package>, no matter if <package> has already been installed. 2) the readline() at the end of install.packages, which asks the user, if the downloaded files should be deleted, makes it difficult to delete packages automatically after installation (I must admit, I'm not quite familiar with R CMD BATCH) Question/Request: Is the behaviour in 1) intended? 2) I'd like to have another bool argument, which determines, if the downloaded files should be deleted. Suggestion: To change 1) I've made a small change to R-2.0.0/src/library/utils/unix/install.packages.R adding one line and moving another one. Here's the diff output --- install.packages.R 2004-10-02 19:07:34.000000000 +0200 +++ install.packages.modified.R 2004-10-22 18:22:01.275986160 +0200 @@ -25,9 +25,9 @@ } if(is.null(available)) available <- CRAN.packages(contriburl = contriburl, method = method) + have <- .packages(all.available = TRUE) if(dependencies) { # check for dependencies, recursively p0 <- p1 <- unique(pkgs) # this is ok, as 1 lib only - have <- .packages(all.available = TRUE) repeat { if(any(miss <- ! p1 %in% row.names(available))) { cat("dependencies ", paste(sQuote(p1[miss]), sep=", "), @@ -54,6 +54,8 @@ } } + pkgs <- pkgs[ ! pkgs %in% have ] + foundpkgs <- download.packages(pkgs, destdir = tmpd, available = available, contriburl = contriburl, method = method) Best Regards, Thomas Stabla -------------- next part -------------- --- install.packages.R 2004-10-02 19:07:34.000000000 +0200 +++ install.packages.modified.R 2004-10-22 18:22:01.275986160 +0200 @@ -25,9 +25,9 @@ } if(is.null(available)) available <- CRAN.packages(contriburl = contriburl, method = method) + have <- .packages(all.available = TRUE) if(dependencies) { # check for dependencies, recursively p0 <- p1 <- unique(pkgs) # this is ok, as 1 lib only - have <- .packages(all.available = TRUE) repeat { if(any(miss <- ! p1 %in% row.names(available))) { cat("dependencies ", paste(sQuote(p1[miss]), sep=", "), @@ -54,6 +54,8 @@ } } + pkgs <- pkgs[ ! pkgs %in% have ] + foundpkgs <- download.packages(pkgs, destdir = tmpd, available = available, contriburl = contriburl, method = method)
On Fri, 22 Oct 2004, Thomas Stabla wrote:> when trying to write an R-file, which automatically installs and updates a > given list of packages,Many of us already have scripts of that sort.> I had two problems with install.packages() > > 1) install.packages("<package>") will install <package>, no matter if > <package> has already been installed. > 2) the readline() at the end of install.packages, which asks the user, if > the downloaded files should be deleted, makes it difficult to > delete packages automatically after installation (I must admit, I'm not > quite familiar with R CMD BATCH) > > > Question/Request: > Is the behaviour in 1) intended?Most definitely. I might want to install it in another library, or to reinstall it under the current version of R. It is very easy to tailor the input to meet your needs, as update.packages() does. There is install.packages() to help you here.> 2) I'd like to have another bool argument, which determines, if the > downloaded files should be deleted.What do you think 'destdir' is there for? If set, this check is skipped. You can set it to tempdir() if you like, which is wiped at the end of the session. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Thomas Stabla wrote:> Hello, > > when trying to write an R-file, which automatically installs and updates a > given list of packages, I had two problems with install.packages() > > 1) install.packages("<package>") will install <package>, no matter if > <package> has already been installed. > 2) the readline() at the end of install.packages, which asks the user, if > the downloaded files should be deleted, makes it difficult to > delete packages automatically after installation (I must admit, I'm not > quite familiar with R CMD BATCH) > > > Question/Request: > Is the behaviour in 1) intended?Yes, if a former installation is broken, we want to be able to reinstall, of course. If you don't want, just check (e.g. via installed.packages()) whether you already got it - or use update.packages().> 2) I'd like to have another bool argument, which determines, if the > downloaded files should be deleted.This might be useful. Are you going to provide a patch? Uwe Ligges> Suggestion: > To change 1) I've made a small change to > > R-2.0.0/src/library/utils/unix/install.packages.R > > adding one line and moving another one. Here's the diff output > > > --- install.packages.R 2004-10-02 19:07:34.000000000 +0200 > +++ install.packages.modified.R 2004-10-22 18:22:01.275986160 +0200 > @@ -25,9 +25,9 @@ > } > if(is.null(available)) > available <- CRAN.packages(contriburl = contriburl, method = > method) > + have <- .packages(all.available = TRUE) > if(dependencies) { # check for dependencies, recursively > p0 <- p1 <- unique(pkgs) # this is ok, as 1 lib only > - have <- .packages(all.available = TRUE) > repeat { > if(any(miss <- ! p1 %in% row.names(available))) { > cat("dependencies ", paste(sQuote(p1[miss]), sep=", "), > @@ -54,6 +54,8 @@ > } > } > > + pkgs <- pkgs[ ! pkgs %in% have ] > + > foundpkgs <- download.packages(pkgs, destdir = tmpd, available = available, > contriburl = contriburl, method = method) > > > > > Best Regards, > Thomas Stabla > > > ------------------------------------------------------------------------ > > --- install.packages.R 2004-10-02 19:07:34.000000000 +0200 > +++ install.packages.modified.R 2004-10-22 18:22:01.275986160 +0200 > @@ -25,9 +25,9 @@ > } > if(is.null(available)) > available <- CRAN.packages(contriburl = contriburl, method = method) > + have <- .packages(all.available = TRUE) > if(dependencies) { # check for dependencies, recursively > p0 <- p1 <- unique(pkgs) # this is ok, as 1 lib only > - have <- .packages(all.available = TRUE) > repeat { > if(any(miss <- ! p1 %in% row.names(available))) { > cat("dependencies ", paste(sQuote(p1[miss]), sep=", "), > @@ -54,6 +54,8 @@ > } > } > > + pkgs <- pkgs[ ! pkgs %in% have ] > + > foundpkgs <- download.packages(pkgs, destdir = tmpd, available = available, > contriburl = contriburl, method = method) > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel