mannau / h5

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

h5file() fails when run from an Rscript #64

Open echomsky opened 7 years ago

echomsky commented 7 years ago

Many thanks for creating and maintaining this package.

It appears that the package is missing some symbols from methods. The following test script runs successfully from an interactive session (which loads methods by default), but fails when run from an Rscript:

#!/usr/bin/env Rscript
library('h5')
fxx <- h5file('test.h5', mode='w')
fxx['data'] <- 1:10
h5close(fxx)

The following error is reported:

Error in initialize(value, ...) :
  cannot use object of class “character” in new():  class “H5File” does not extend that class
Calls: h5file -> new -> initialize -> initialize
6: (function ()
   traceback(2))()
5: stop(gettextf("cannot use object of class %s in new():  class %s does not extend that class",
       dQuote(Classi), dQuote(Class)), domain = NA)
4: initialize(value, ...)
3: initialize(value, ...)
2: new("H5File", name, mode)
1: h5file("test.h5", mode = "w")

The Rscript runs successfully if methods is explicitly loaded before h5:

#!/usr/bin/env Rscript
library('methods')
library('h5')
fxx <- h5file('test.h5', mode='w')
fxx['data'] <- 1:10
h5close(fxx)
sunyj commented 6 years ago

I have exactly same problem too.

sunyj commented 6 years ago

Use R_DEFAULT_PACKAGES= Rscript xxx.R solves the problem

sunyj commented 6 years ago

Well I believe it's a bug in h5, please refer to this: https://stat.ethz.ch/pipermail/r-devel/2017-December/075311.html

YSanchezAraujo commented 6 years ago

@sunyj could you please expand on your explanation of R_DEFAULT_PACKAGES= Rscript xxx.R to solve this issue? Perhaps by providing a more concrete example?

EDIT: never mind, got it

adfaure commented 6 years ago

Hi, it took me a while to understand your answer @sunyj, but indeed, it works for me too.

To add a bit of context: Instead of using, to execute a script in a bash.

$ Rscript myScript.R

one need to prefix the command by R_DEFAULT_PACKAGES=.

$ R_DEFAULT_PACKAGES= Rscript myScript.R