JuliaSwitch is a high-level R–Julia interface. The package
provides a common syntax that enables users to switch between multiple
backends for R–Julia communication without changes to the code base.
- Run
Juliacode via ajulia_*()helper function orjulia_cmd_line()/julia_cmd_block(); - Push objects to
Juliausingjulia_push(); - Pull objects back via
julia_pull();
JuliaSwitch was motivated our work on animal tracking with patter.
This package provides an R interface to Patter.jl, which fit
state-space models to animal-tracking data in Julia.
When
patterwas first developed, we usedJuliaCallas aR–Juliainterface. That package connectsRandJuliavia aCinterface, which is fast but can be unstable acrossJuliaversions and platforms. (We experienced particular challenges on Linux when usingRandJuliapackages that require the same dynamic libraries.)
JuliaConnectoRis anotherR–Juliaoption. UnlikeJuliaCall, this package interfacesRandJuliausing Transmission Control Protocol. This is a looser form of integration which trades speed for stability.
JuliaSwitch became the solution to toggle between these two options.
JuliaSwitch can be installed with:
install.packages("devtools")
devtools::install_github("edwardlavender/JuliaSwitch",
dependencies = TRUE)-
Run
julia_backend("JuliaCall")orjulia_backend("JuliaConnectoR")to set theJuliabackend. -
Start a
Juliasession viajulia_start(). -
Run arbitrary
Juliacode viajulia_cmd_line()andjulia_cmd_block(). -
For selected operations, helper functions are provided:
julia_pkg_activate()activates a local environment;julia_pkg_add()adds packages;julia_using()andjulia_import()load and import packages;julia_include()sourcesJuliascripts;julia_println()prints lines;julia_save()andjulia_load()save and load files;
-
To push objects from
RtoJulia, usejulia_push(). -
To pull objects back from
JuliatoR, usejulia_pull(). -
Stop a
Juliasession viajulia_stop().
JuliaSwitch uses S3 methods to handle object transfers between R
and Julia. Method dispatch is implemented by the internal functions
julia_allot(), juliaAllot() and juliaTranslate().The default
methods call the relevant JuliaCall or JuliaConnectoR routines.
Special cases (such as data.frames and terra::SpatRasters) are
handled by custom methods. Specify additional methods for other special
cases.
Please note that the JuliaSwitch project is released with a
Contributor Code of
Conduct.
By contributing to this project, you agree to abide by its terms.