0

I've some strange problems regarding R and Rscript. I'm using a bunch of scripts to read/write hdf files using the h5 package. In R Studio, everything works fine. As i want to execute my scripts automatically, I'm using the Windows Task Scheduler and rscript to execute the code, but this fails whenever i want to open a hdf file using

myfile <- h5file('somefilename', mode ='a')

The error reported is

Error in initialize(value, ...): cannot use object of class "character" in new(): class "H5File" does not extend that class

The h5 package is loaded and all the code works fine if i'm using RStudio. Any ideas?

many thanks & best regards Wolf

Update: I've edited the testfile to create some additional output:

ll=library(h5, verbose = TRUE)
fc <- file("c:/temp/rlog.txt")
writeLines(search(), fc)
close(fc)
myfile <- h5file('c:/temp/testfile.h5', mode ='a')

The error is the same, output from search() (in the rlog.txt file):

.GlobalEnv
package:h5
package:stats
package:graphics
package:grDevices
package:utils
package:datasets
Autoloads
package:base
wolferman
  • 23
  • 3
  • My guess would be that path to the file is incorrect. Rstudio will adjust `getwd()` based on your project or set it to `~/Documents` where you might have the file. In any case, it's hard to judge without more information. – Roman Luštrik Oct 05 '17 at 09:35
  • The filename shouldn't be a problem, if the file is not found then a new one will be created. Also, i'm using absolute file names. What kind of additional information is needed? Even if i'm just using the `myfile <- h5file('fname',mode = 'a')', the code will not execute in rscript... – wolferman Oct 05 '17 at 09:47
  • 1
    Enough information which will enable us determine or suspect root cause. Which information is that? At your discretion. Code, data, output... – Roman Luštrik Oct 05 '17 at 09:55
  • Thoe code is exactly as stated above, myfile <- h5file('somefilename', mode ='a'). For testing purpose, I've created a script that only contains the single line of code above (plus the library(h5)). Runs fine in RStudio, but not with rScript. Also the error message is exactly as stated above – wolferman Oct 05 '17 at 11:06
  • Probably the good old issue of [Rscript not loading package `methods`](https://stackoverflow.com/questions/34297634/cv-glmnet-works-in-rstudio-but-not-rscript). Just add `library(methods)`. – Dirk Eddelbuettel Oct 05 '17 at 11:30
  • @Dirk: That did it! I've already tried this before, but i've loaded methods AFTER h5, but it seems to be important that methods is loaded first. Please post it as answer, so I can close the question. Many thanks! – wolferman Oct 05 '17 at 11:42
  • I answered this half a dozen times already, just upvote the one I'll mark this as a duplicate of. – Dirk Eddelbuettel Oct 05 '17 at 11:48

0 Answers0