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

View source: R/main.R

juliaLetR Documentation

Evaluate Julia code in a let block using values of R variables

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

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

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 Oct. 9, 2024, 1:08 a.m.