floidgilbert / jsr223 Goto Github PK
View Code? Open in Web Editor NEWA Java Platform Integration for R with Programming Languages Groovy, JavaScript, JRuby (Ruby), Jython (Python), and Kotlin
License: BSD 3-Clause "New" or "Revised" License
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
This is currently a common issue involving the Kotlin implementation on Windows. The simplest workaround is to follow the instructions in the jsr223 vignette for installing the Kotlin script engine. Essentially, Kotlin is looking for some files in the \bin
folder. The warning arises when these files are not present.
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.
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.
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.
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")
The jsr223 (and jdx) package does not support Groovy strings directly. Workaround: convert them to strings before pulling/pushing into R. We don't offer support for this type because it complicates code used to infer types and structures relating to collections and object arrays. In short, it just isn't worth it.
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.
This is a bug that has been reported to Kotlin (KT-22398). The following code example demonstrates the problem. Currently, there is no workaround.
engine$setStandardOutputMode("quiet")
engine %@% 'print("you should not see this message.")'
engine$setStandardOutputMode("buffer")
engine %@% 'print("you should not see this message.")'
engine$getStandardOutput() # Returns an empty string
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.