As from R 2.5.0 users can install packages in their home directories, in
directory specified by the environment variable R_LIBS_USER. It's a
great feature.
But I have a problem with this feature, when R_LIBS is defined.
It works well the first time, when R creates the directory defined in
R_LIBS_USER.
> install.packages('BayesTree')
Warning in install.packages("BayesTree") :
argument 'lib' is missing: using '/usr/lib64/R/lib'
Warning in install.packages("BayesTree") :
'lib = "/usr/lib64/R/lib"' is not writable
Would you like to create a personal library
'~/R/x86_64-mandriva-linux-gnu-library/2.7'
to install packages into? (y/n) y
.....
> q()
But if you close R, then launch R again, R fails to reuse this directory
(R_LIBS_USER) to install another package, because the directories
defined in R_LIBS are in first in the libPaths (and it fails if R_LIBS
isn't writable by user).
> .libPaths()
[1] "/usr/lib64/R/lib"
[2] "/home/menut/R/x86_64-mandriva-linux-gnu-library/2.7"
[3] "/usr/lib64/R/library"
> install.packages('BayesValidate')
Warning in install.packages("BayesValidate") :
argument 'lib' is missing: using '/usr/lib64/R/lib'
Warning in install.packages("BayesValidate") :
'lib = "/usr/lib64/R/lib"' is not writable
Error in install.packages("BayesValidate") : unable to install packages
I attach a patch, which try to reuse existing user directory R_LIBS_USER
(tested under Linux).
with this patch
> .libPaths()
[1] "/usr/lib64/R/lib"
[2] "/home/menut/R/x86_64-mandriva-linux-gnu-library/2.7"
[3] "/usr/lib64/R/library"
> install.packages('BayesValidate')
Warning in install.packages("BayesValidate") :
argument 'lib' is missing: using '/usr/lib64/R/lib'
Warning in install.packages("BayesValidate") :
'lib = "/usr/lib64/R/lib"' is not writable
Warning in install.packages("BayesValidate") :
using '~/R/x86_64-mandriva-linux-gnu-library/2.7'
...
Please could you review it and tell me if such things are worth
including into upstream version.
Best regards,
Luc
--
Luc MENUT
diff -Naur R-2.7.0.orig/src/library/utils/R/packages2.R
R-2.7.0/src/library/utils/R/packages2.R
--- R-2.7.0.orig/src/library/utils/R/packages2.R 2008-04-10
04:05:02.000000000 +0200
+++ R-2.7.0/src/library/utils/R/packages2.R 2008-05-25 00:04:25.000000000
+0200
@@ -134,7 +134,29 @@
domain = NA, immediate. = TRUE)
userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"),
.Platform$path.sep))[1]
- if(interactive() && !file.exists(userdir)) {
+ if (file.exists(userdir)) {
+ ## check for writability of userdir by user
+ ok <- file.info(userdir)$isdir & (file.access(userdir, 2) == 0)
+ if(length(userdir) == 1 && .Platform$OS.type == "windows") {
+ ## file.access is unreliable on Windows, especially Vista.
+ ## the only known reliable way is to try it
+ ok <- file.info(userdir)$isdir
+ if(ok) {
+ fn <- file.path(userdir, "_test_dir_")
+ unlink(fn, recursive = TRUE) # precaution
+ res <- try(dir.create(fn, showWarnings = FALSE))
+ if(inherits(res, "try-error") || !res) ok <- FALSE
+ else unlink(fn, recursive = TRUE)
+ }
+ }
+ if (ok) {
+ lib <- userdir
+ warning(gettextf("using '%s'", lib),
+ immediate. = TRUE, domain = NA)
+ }
+ else stop(sQuote(userdir), "\nis not a writable directory, unable
to install packages")
+ } else {
+ if(interactive()) {
msg <- gettext("Would you like to create a personal
library\n'%s'\nto install packages into?")
if(.Platform$OS.type == "windows") {
ans <- winDialog("yesno", sprintf(msg, userdir))
@@ -147,7 +169,8 @@
stop("unable to create ", sQuote(userdir))
lib <- userdir
.libPaths(c(userdir, .libPaths()))
- } else stop("unable to install packages")
+ } else stop("unable to install packages")
+ }
}
if(.Platform$OS.type == "windows") {
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel