mannau / h5

Interface to the HDF5 Library
Other
70 stars 22 forks source link

Rscript cannot be run on anything that uses h5 #52

Closed epipping closed 7 years ago

epipping commented 7 years ago

I was trying to run Rscript on a script that uses h5. Here's the minimal sample code (which I'll place in the file foo.R):

file <- h5::h5file("/tmp/test.h5")

Running this through R CMD BATCH works just fine:

% rm -f /tmp/test.h5; R CMD BATCH --vanilla foo.R; cat foo.Rout
[..]
> file <- h5::h5file("/tmp/test.h5")
> 
> proc.time()
   user  system elapsed 
  0.302   0.031   0.324 
% 

Loading it from within R works, too:

% rm -f /tmp/test.h5; R --vanilla
[..]
> source('foo.R')
> 

Yet Rscript fails spectacularly:

% rm -f /tmp/test.h5; Rscript --vanilla foo.R
[..]
Error in initialize(value, ...) : 
  cannot use object of class "character" in new():  class "H5File" does not extend that class
Calls: <Anonymous> -> new -> initialize -> initialize
Execution halted
% 
epipping commented 7 years ago

As much as the error is cryptic and not helpful... I've now figured out that one needs to load methods here, e.g. by adding library(methods) to the start of the script or invoking Rscript via

Rscript --vanilla --default-packages=methods foo.R