From murdoch.duncan at gmail.com  Wed Dec 27 12:13:12 2017
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Wed, 27 Dec 2017 06:13:12 -0500
Subject: [Rd] Rscript fails with some packages (for example, h5)
In-Reply-To: <23106.24430.6935.8034@bud.eddelbuettel.com>
References: <CAL109eMo37PYMgE8KV0rxBgCGe-6Z1NhPrsUiQJfqCoJXfk6CA@mail.gmail.com>
 <23106.17557.985432.335423@bud.eddelbuettel.com>
 <CAL109eMSq6=mbSzrMnktNiOw=z5C=Tj7nDg9o4zNir-h5pCywg@mail.gmail.com>
 <23106.24430.6935.8034@bud.eddelbuettel.com>
Message-ID: <9467e2c6-55b4-5e70-dfd4-9891eb02a25b@gmail.com>

On 26/12/2017 9:40 AM, Dirk Eddelbuettel wrote:
> 
> On 26 December 2017 at 22:14, Sun Yijiang wrote:
> | Thanks for the solution.  Now I know the work-arounds, but still don't
> | quite get it. Why does R_DEFAULT_PACKAGES has anything to do with
> | library(methods)?
> 
> Because it governs which packages are loaded by default.  And while R also
> loads 'methods', Rscript does not. Source of endless confusion.

Mostly irrelevant correction of the jargon:  that setting controls which 
packages are "attached" by default.  library(h5) would be enough to load 
methods, because h5 imports things from methods.  But loading doesn't 
put a package on the search list.  library(methods) both loads methods 
(if it hasn't already been loaded), and attaches it.

> 
> | If library(h5) works, it should just work, not depend on an environment variable.
> 
> Every package using S4 will fail under Rscript unless 'methods' explicitly.

That's not quite true (or quite English, as per fortune(112)).  The 
"gmp" package imports methods, and it works in Rscript.  What doesn't 
work is to expect library(h5) or library(gmp) to cause methods functions 
like show() to be available to the user.

There is a way to do that, but it is discouraged nowadays. My ancient 
package "orientlib" depends on methods, and that forces methods to be 
attached so show() works in Rscript.  ("Depends" is used in the 
DESCRIPTION file sense.)  h5 doesn't "depend" on methods, it "imports" 
methods.


> 
> | Rscript is not consistent with R, that's my confusion.
> 
> Indeed. And you are not the first person confused by it.

And that's still true, and less irrelevant than my corrections.

Duncan Murdoch



[Rd] Rscript fails with some packages (for example, h5)
Duncan Murdoch