if (juliaSetupOk()) {
# Importing a package and using one of its exported functions
UUIDs <- juliaImport("UUIDs")
juliaCall("string", UUIDs$uuid4())
# Importing a module without a package
testModule <- system.file("examples", "TestModule1.jl",
package = "JuliaConnectoR")
# take a look at the file
writeLines(readLines(testModule))
# load in Julia
juliaCall("include", testModule)
# import in R via relative module path
TestModule1 <- juliaImport(".TestModule1")
TestModule1$test1()
# Importing a local module is also possible in one line,
# by directly using the module object returned by "include".
TestModule1 <- juliaImport(juliaCall("include", testModule))
TestModule1$test1()
# Importing a submodule
testModule <- system.file("examples", "TestModule1.jl",
package = "JuliaConnectoR")
juliaCall("include", testModule)
# load sub-module via module path
SubModule1 <- juliaImport(".TestModule1.SubModule1")
# call function of submodule
SubModule1$test2()
# Functions using non-ASCII characters
greekModule <- system.file("examples", "GreekModule.jl",
package = "JuliaConnectoR")
suppressWarnings({ # importing gives a warning on non-UTF-8 locales
GreekModule <- juliaImport(juliaCall("include", greekModule))
})
# take a look at the file
cat(readLines(greekModule, encoding = "UTF-8"), sep = "\n")
# use alternative names
GreekModule$``(1)
GreekModule$`log`(1)
}
# \dontshow{
JuliaConnectoR:::stopJulia()
# }
Run the code above in your browser using DataLab