Skip to content

A high-level R-Julia interface that wraps `JuliaCall` and `JuliaConnectoR` with a common syntax

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

edwardlavender/JuliaSwitch

Repository files navigation

JuliaSwitch

Lifecycle: experimental CRAN status

JuliaSwitch is a high-level RJulia interface. The package provides a common syntax that enables users to switch between multiple backends for RJulia communication without changes to the code base.

  • Run Julia code via a julia_*() helper function or julia_cmd_line()/julia_cmd_block();
  • Push objects to Julia using julia_push();
  • Pull objects back via julia_pull();

Motivation

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 patter was first developed, we used JuliaCall as a RJulia interface. That package connects R and Julia via a C interface, which is fast but can be unstable across Julia versions and platforms. (We experienced particular challenges on Linux when using R and Julia packages that require the same dynamic libraries.)

JuliaConnectoR is another RJulia option. Unlike JuliaCall, this package interfaces R and Julia using 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.

Installation

JuliaSwitch can be installed with:

install.packages("devtools")
devtools::install_github("edwardlavender/JuliaSwitch", 
                         dependencies = TRUE)

Functionality

  • Run julia_backend("JuliaCall") or julia_backend("JuliaConnectoR") to set the Julia backend.

  • Start a Julia session via julia_start().

  • Run arbitrary Julia code via julia_cmd_line() and julia_cmd_block().

  • For selected operations, helper functions are provided:

    • julia_pkg_activate() activates a local environment;
    • julia_pkg_add() adds packages;
    • julia_using() and julia_import() load and import packages;
    • julia_include() sources Julia scripts;
    • julia_println() prints lines;
    • julia_save() and julia_load() save and load files;
  • To push objects from R to Julia, use julia_push().

  • To pull objects back from Julia to R, use julia_pull().

  • Stop a Julia session via julia_stop().

S3 methods

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.

Code of conduct

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.

About

A high-level R-Julia interface that wraps `JuliaCall` and `JuliaConnectoR` with a common syntax

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages