RCall.jl - how to handle R package dependencies?

Hi there,

I’m working on an experimental feature for CounterfactualExplanations.jl that adds native support for explaining R torch models. This is made possible by RCall.jl and local tests are passing. But since torch is not a standard library in R, my CI workflow fails (as it should). So I’m wondering:

Q1: Is there an elegant/preferred way to install R package dependencies on load?

I’m conscious that by having my Julia package depend on R package I might be opening up a can of worms, but having native support for this kind of interoperability would be awesome. I’m planning to restrict myself to torch and perhaps one or two other packages in the long run. Still, I’m wondering:

Q2: Is relying on deps of other languages utter madness or feasible?

function __init__()
   only(rcopy(R"""require("mypkg")""")) && return nothing
   @info "mypkg not available in R, installing now...."
   reval("""install.packages("mypkg", method="wget", repos="https://cloud.r-project.org")""")
   reval("""library("mypkg")""")
   return nothing
end
"""

require returns a boolean about whether a package was successfully loaded, while library errors if the package can’t be loaded.

3 Likes