juliaLet: Evaluate Julia code in a 'let' block using values of R...

Description Usage Arguments Details Value Examples

View source: R/main.R

Description

R variables can be passed as named arguments, which are inserted for those variables in the Julia expression that have the same name as the named arguments. The given Julia code is executed in Julia inside a let block and the result is translated back to R.

Usage

1
juliaLet(expr, ...)

Arguments

expr

Julia code, given as one-element character vector

...

arguments that will be introduced as variables in the let block. The values are transferred to Julia and assigned to the variables introduced in the let block.

Details

A simple, nonsensical example for explaining the principle:

juliaLet('println(x)', x = 1)

This is the same as

juliaEval('let x = 1.0; println(x) end')

More complex objects cannot be simply represented in a string like in this simple example any more. That is the problem that juliaLet solves.

Note that the evaluation is done in a let block. Therefore, changes to global variables in the Julia session are only possible by using the keyword global in front of the Julia variables (see examples).

Value

The value returned from Julia, translated to an R data structure. If Julia returns nothing, an invisible NULL is returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
if (juliaSetupOk()) {

   # Intended use: Create a complex Julia object
   # using Julia syntax and data from the R workspace
   juliaLet('[1 => x, 17 => y]', x = rnorm(1), y = rnorm(2))

   # Assign a global variable
   # (although not recommended for a functional style)
   juliaLet("global x = xval", xval = rnorm(10))
   juliaEval("x")

}

JuliaConnectoR documentation built on Jan. 27, 2022, 1:12 a.m.