4

I'm new to Rscript so please bear with me, I need to execute a R script (written by another developer) from java and for that I'm using Renjin. The R script file and other required files are on classpath i.e. under resources folder.

To achieve this I'm loading Rscript from classpath and it gets loaded successfully, and Rscript tries to load a abc.Rda file internally which is also present in classpath (parallel to R script), the code for same is below

load('abc.Rda')

But when I try to execute script then it throws exception as below:

Could not read from "file:///D:/data/{project-dir}/abc.Rda" because it is a not a file.

Please suggest where I'm making mistake.

9
  • Did you try to give absolute file path to function? Commented Jun 29, 2016 at 6:38
  • Yup tried that, but the problem is same Commented Jun 29, 2016 at 7:33
  • I've tried various tests but wasn't able to produce any errors: single, double quotes, capitalized file extension when actual is lower case, etc. save(d, file='abc.rda') load('abc.Rda') Commented Jul 4, 2016 at 20:41
  • Could you try load('abc.Rda', verbose = TRUE) to see if it gives any more clues? Also, maybe you could look into character encoding: stackoverflow.com/questions/34024654/… Commented Jul 4, 2016 at 22:20
  • What's in the Rda file? Could this be related to or a regression of github.com/bedatadriven/renjin/issues/106? (I'm assuming that the R code works without error if run outside of renjin.) Commented Jul 5, 2016 at 5:42

1 Answer 1

1

I'm not sure why using the absolute path didn't work: perhaps the script is incorrectly calling setwd(dir='/bad/{project-dir}') somewhere earlier?

Renjin actually mediates file system operations through Apache Virtual File System (VFS). So if you specifically want a resource on the classpath, you can use the "res:" protocol, for example:

load('res:com/acme/mypackage/abc.Rda')

This should work whether the file is actually on the filesystem or packaged as part of a jar or other archive.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.