Coder Social home page Coder Social logo

floidgilbert / jsr223 Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 1.0 76.15 MB

A Java Platform Integration for R with Programming Languages Groovy, JavaScript, JRuby (Ruby), Jython (Python), and Kotlin

License: BSD 3-Clause "New" or "Revised" License

R 84.94% Java 15.06%
java r jython jruby kotlin javascript groovy rjava

jsr223's People

Contributors

dbdahl avatar floidgilbert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mutual-ai

jsr223's Issues

Wild cards in class paths are not supported.

Wild cards in class paths are not supported. In jsr223 version <= 0.3.1, "lib/*" will throw an error indicating the path "lib/*" does not exist. As of version 0.3.2, an error will be thrown indicating wild cards are not supported.

Though Java supports "lib/*" style wild cards (see Setting the class path), rJava does not support them. (jsr223 uses rJava to interface with the Java Virtual Machine.)

We considered supporting wild cards in a typical file system style by listing the appropriate files, but this is not typical class path behavior. Therefore, we suggest you use the R function list.files or some equivalent.

Support for Scala JSR-223 implementation.

The jsr223 project does not officially support the Scala JSR-223 implementation. The primary reason is because Scala's implementation is not fully developed. Instead, we recommend that you use the rscala package. It provides a mature, in-depth integration between Scala and R.

Different script engine instances in the same R session share an accumulated class path. Furthermore, restarting a script engine does not clear the class path.

The short answer
The only way to clear the class path is to restart the R session. This is a limitation of the rJava package that jsr223 depends on.

The explanation
The jsr223 package depends on rJava to manage low-level JVM operations. Using rJava, one R session corresponds to a single in-process JVM. Hence, all Java objects share the same class path. Currently, rJava does not provide a facility to remove entries from the class path. As a result, whenever a new script engine is instantiated with a new class path, the unique entries accumulate in the class path. The only way to clear the class path is to restart the JVM. The only way to restart the JVM is to restart the R session.

Calling Kotlin methods from R: invokeMethod returns "java.lang.IllegalStateException: receiverKlass.java.classLoader must not be null"

invokeMethod fails in Kotlin. This is a reported bug: KT-22414. There is a workaround: add the reference to the Kotlin bindings as in this example.

engine %@% "class A {fun f(): Int {return 8}}"
engine %@% "val a = A()"
engine %@% "a.f()"

# This line fails
engine$invokeMethod("a", "f")

# After adding the reference to bindings, the call works.
engine %@% "jsr223Bindings[\"a\"] = a"
engine$invokeMethod("a", "f")

“Failed to instantiate engine '<engine name>'. Make sure the engine dependencies are in the class path.”

This error may occur even when the dependencies are included correctly in the class path. This usually indicates a conflict or some other problem related to the class path. Usually, using fully-qualified paths resolves this error. As of version 0.3.2, jsr223 will automatically qualify class paths.

If using fully-qualified paths doesn't help, restart R. See this rJava issue for more information.

If the above remedies don't help, your class path may be incorrect or one or more JAR files may be corrupt.

Kotlin global `bindings` object is read-only.

The Kotlin global bindings object in the Kotlin script engine is read-only. This bug has been reported to Kotlin (KT-18917). Use the jsr223Bindings global object instead. See the example below.

library("jsr223")

# Change this path to the installation directory of the Kotlin compiler.
kotlin.directory <- Sys.getenv("KOTLIN_HOME")

engine <- ScriptEngine$new(
  engine.name = "kotlin",
  class.path = getKotlinScriptEngineJars(kotlin.directory)
)

# Establish a binding named `a`
engine$a <- 1
engine$a

# Access bindings via the global `bindings` object in the Kotlin script engine
# environment. Be sure to use double quotes as the string delimiter within the
# Kotlin script. The following two expressions are equivalent.
engine %~% 'bindings["a"]'
engine %~% 'bindings.get("a")'

# The `bindings` object appears to be of javax.script.SimpleBindings.
engine %~% 'bindings::class.qualifiedName'

# However, the object does not support updates. The following line would throw
# an error. See https://youtrack.jetbrains.com/issue/KT-18917
# engine %~% 'bindings.put("a", 2.1);'

# This is a known bug. The workarounds are to cast `bindings` as
# javax.script.Bindings or to use `jsr223Bindings`.
engine %@% 'jsr223Bindings.put("a", 4.1)'
engine$a

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.