juliaImport | R Documentation |
import
statementThe specified package/module is loaded via import
in Julia.
Its functions and type constructors are wrapped into R functions.
The return value is an environment containing all these R functions.
juliaImport(modulePath, all = TRUE)
modulePath |
a module path or a module object.
A module path may simply be the name of a package but it may also
be a relative module path.
Specifying a relative Julia module path like |
all |
|
an environment containing all functions and type constructors from the specified module as R functions
If a package or module contains functions or types with names that contain
non-ASCII characters, (additional) alternatives names are provided
if there are LaTeX-like names for the characters available in Julia.
In the alternative names of the variables, the LaTeX-like names of the
characters surrounded by <...>
replace the original characters.
(See example below.)
For writing platform independent code, it is recommended to use those
alternative names.
(See also JuliaConnectoR-package under "Limitations".)
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$`<sigma>`(1)
GreekModule$`log<sigma>`(1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.