Has Anyone Used RCall with `renv`?

Hi all!

Just was wondering if anyone has had any luck with using renv with RCall.
In R, I use renv to manage my package versions per project (very similar to lock files in Julia) and usually you can activate renv easily at start-up of the R REPL.
Anyone have any experiences that they could share on using these tools together?
Thank you!

~ tcp :deciduous_tree:

2 Likes

I found that the combination of the two just worked. renv hooks into the REPL by creating a .Rprofile file in your working directory. RCall reads that .Rprofile when you first run using RCall, so renv gets activated as expected. You can run commands like renv::status() and renv::install() through the dollar-sign shell mode or by running R command strings like R"renv::status()". And if it doesn’t get activated for some reason, you can run the activation script manually with source("renv/activate.R").

Here’s what my workflow looked like:

# start julia in workdir with julia --project=.
julia> import Pkg; Pkg.add("RCall")
julia> using RCall
# $ activates R repl mode
R> renv::init()
R> renv::install('tidyverse')
R> library(tidyr)
# have at it
# upon restarting the julia repl, `using RCall` will activate renv again
3 Likes

Oh, you need renv installed system-wide for that to work, but that’s how I have my R environment set up anyway. renv is the only thing I have installed system-wide and I do everything else in renv projects.