Question

I'm experimenting the jvmr package to run Scala from R. I'm not able to import a library from a local file.

For example, that works for the java.io._ library :

a <- scalaInterpreter()
a['import java.io._'] 

but I don't know where it finds this library.

Now in order to import a jar library from a local folder, I have tried to set the class path using these two ways but none works :

1- set the current directory of Scala (through the Scala interpreter) to the library folder

2- add the path of the library in the java.class.path system variable of Scala, as follows:

java.class.path <- a['System.getProperty("java.class.path")']
java.class.path <- paste0("pathtomyjar:", java.class.path)
a['val jcpath="${1}"', java.class.path]
a['System.setProperty("java.class.path", jcpath)']
Was it helpful?

Solution

Running

a <- scalaInterpreter("pathtomyjar.jar")

in R is similar to

scala -classpath pathtomyjar.jar

and that's the way to go.

To add several jars, use a vector in R :

a <- scalaInterpreter(c("pathtomyjar1.jar","pathtomyjar2.jar"))

is similar to

scala -classpath pathtomyjar1.jar:pathtomyjar2.jar
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top