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().
Arguments
- stop
If
TRUE, stop active Julia session. Defaults toFALSE.- 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 variableJULIA_NUM_THREADSand restart Julia if it is already running to apply the new thread setting. See this page for more details on threading in Julia.- quiet
If
TRUE, suppress informational messages such as progress and status updates. Warnings and errors are always shown. Defaults toFALSE.
Value
Returns TRUE invisibly after setting up the Julia environment, and NULL invisibly if Julia was already set up or when stopping Julia with stop = TRUE. Used for side effects.
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.
Examples
# Start a Julia session and activate the Julia environment for sdbuildR
use_julia()
#> ℹ Activating Julia environment for sdbuildR at
#> /home/runner/.local/share/R/sdbuildR/julia...
#> ✔ Julia environment ready.
# Start Julia with 2 threads (only works if threading is supported)
use_julia(nthreads = 2)
#> ℹ Activating Julia environment for sdbuildR at
#> /home/runner/.local/share/R/sdbuildR/julia...
#> ✔ Julia environment ready with 2 threads.
# Restart Julia session (in case of issues)
use_julia(restart = TRUE)
#> ✔ Closed Julia session.
#> ℹ Activating Julia environment for sdbuildR at
#> /home/runner/.local/share/R/sdbuildR/julia...
#> ✔ Julia environment ready.
# Stop Julia session
use_julia(stop = TRUE)
#> ✔ Closed Julia session.