purrr2for icon indicating copy to clipboard operation
purrr2for copied to clipboard

Automagically Convert purrr R Calls to Efficient Julia for Loops

purrr2for

Concerned about R performance?

Automagically convert R/purrr syntax code blocks into efficient Julia for loops with a simple Addin. No writing of Julia/RCpp code itself, the converter is feature-complete with both R's purrr and *pply family and writes the required Julia code.

Installation

You can install the released version of purrr2for from GitHub with:

devtools::install_github("jonocarroll/purrr2for")

Example

If you have a code block written in R (purrr or *pply loop)

map(1:10, function(x) x^2)

the Addin will convert this into a Julia call for you

map(x -> x^2, 1:10)

This can be wrapped in a JuliaCall block and run inline.

Benchmarks

Unit: microseconds
                              expr     min      lq      mean  median       uq      max neval cld
purrr::map(1:10, function(x) 10^2) 249.332 260.999 289.59205 265.926 286.9025 1474.852   100   b
       [Julia] map(x -> x^2, 1:10)  29.030  32.084  57.02304  36.705  38.8305 1917.149   100  a