Archive | May, 2017

call Kotlin from R

15 May


  1. Download & Install kotlin command line compiler
  2. install rJava in R
    (in Ubuntu, you might want to point /usr/lib/jvm/default-java to the jvm you installed)
  3. create a kotlin class, e.g.
    // User.kt
    data class User(name: String, age: Int)
  4. In R
    # add path to User.class and kotlin runtime
    .jaddClassPath(c("./", "/usr/local/kotlinc/lib/kotlin-runtime.jar"))
    tom <- .jnew("User", "Tom", as.integer(20))
    .jcall(tom, "S", "getName")
    .jcall(tom, "I", "getAge")