From sunyijiang at gmail.com  Tue Dec 26 08:24:19 2017
From: sunyijiang at gmail.com (Sun Yijiang)
Date: Tue, 26 Dec 2017 15:24:19 +0800
Subject: [Rd] Rscript fails with some packages (for example, h5)
Message-ID: <CAL109eMo37PYMgE8KV0rxBgCGe-6Z1NhPrsUiQJfqCoJXfk6CA@mail.gmail.com>

Consider this script (with h5 installed):

$ cat test.R
library(h5)
name <- tempfile()
f <- h5file(name)
file.remove(name)

$ Rscript test.R
Error in initialize(value, ...) :
  cannot use object of class "character" in new():  class "H5File" does not
extend that class
Calls: h5file -> new -> initialize -> initialize
Execution halted

$ /usr/lib64/R/bin/R --slave --no-restore --file=test.R
[1] TRUE

$ R_DEFAULT_PACKAGES= Rscript test.R
[1] TRUE

$ R
> source('test.R')
>

$ R_DEFAULT_PACKAGES='datasets,utils,grDevices,graphics,stats' R
> source('test.R')
Error in initialize(value, ...) :
  cannot use object of class "character" in new():  class "H5File" does not
extend that class
>

After looking into C source code, I found that Rscript by default fills
environment variable R_DEFAULT_PACKAGES with
"datasets,utils,grDevices,graphics,stats", and it somehow fails some
package like h5.

The problem here is, not setting R_DEFAULT_PACKAGES is equivalent to
setting it to a magic value, it's really confusing.  I suggest remove this
feature.

	[[alternative HTML version deleted]]



[Rd] Rscript fails with some packages (for example, h5)
Sun Yijiang