Learn R Programming

sdbuildR (version 2.0.0)

use_julia: Start Julia and activate environment

Description

Start Julia session and activate Julia environment to simulate stock-and-flow models. To do so, Julia needs to be installed (see https://julialang.org/install/) and findable from within R. See this vignette for guidance. In addition, the Julia environment specifically for sdbuildR needs to have been instantiated. This can be set up with install_julia_env().

Usage

use_julia(stop = FALSE, restart = FALSE, nthreads = NULL)

Value

Returns NULL invisibly, used for side effects

Arguments

stop

If TRUE, stop active Julia session. Defaults to FALSE.

restart

If TRUE, force Julia session to restart.

nthreads

If not NULL, set the number of threads for Julia to use. This will temporarily set the environment variable JULIA_NUM_THREADS and restart Julia if it is already running to apply the new thread setting. See this page for more details on threading in Julia.

Details

In every R session, use_julia() needs to be run once (which is done automatically in simulate()), which can take around 30-60 seconds.

See Also

install_julia_env()

Examples

Run this code
if (FALSE) { # Sys.getenv("NOT_CRAN") == "true"
# Start a Julia session and activate the Julia environment for sdbuildR
use_julia()

# Start Julia with 2 threads (only works if threading is supported)
use_julia(nthreads = 2)

# Restart Julia session (in case of issues)
use_julia(restart = TRUE)

# Stop Julia session
use_julia(stop = TRUE)
}

Run the code above in your browser using DataLab