JuliaConnectoR icon indicating copy to clipboard operation
JuliaConnectoR copied to clipboard

Utility functions for package developers

Open s3alfisc opened this issue 3 years ago • 4 comments

Hi Stefan & coauthors,

First of all, JuliaConnectoR is a joy to work with - running Julia from R works like a charm!

At the moment, I am working on an R wrapper package of @droodman's WildBootTests.jl package. In order for the wrapper package (with its superior implementation of the wild cluster bootstrap) to be wildly used, it is critical that the installation of all Julia components is as easy as possible for Julia-inexperienced R users (but also more experienced R users might struggle a bit with setting environmental variables). I believe that setting up a set of "template" functions that standardizes downloading Julia & connecting Julia and R would greatly facilitate the integration of Julia code into R software.

I have invested a little bit into a smooth installation experience - the utilities for wildboottestjlr currently depend on the usethis and JuliaCall packages & it would be great to cut down on these dependencies.

E.g. in the wildboottestjlr_setup function, I

  • install Julia via JuliaCall::install_julia()
  • connect Julia and R by opening the renviron file via usethis::edit_r_environ() and give an explanation what to paste in there via a message
  • install WildBootTests.jl by running
 JuliaConnectoR::juliaEval("using Pkg")
 JuliaConnectoR::juliaEval('Pkg.add("WildBootTests")')
 cat("Pre-compile WildBootTests.jl. This might take a few seconds.", "\n")
 JuliaConnectoR::juliaEval("using WildBootTests")

I think it would be a great idea to add a set of utility function to JuliaConnectoR or to write a custom package, e.g. JuliaConnectoR.utils that package developers can import as a dependency which makes all these things extremely convenient.

Such a package would preferably make it easy to

  1. download Julia and all required Julia packages with version number specified in the description field or higher
  2. connect Julia and R via JuliaConnectoR
  3. set Julia environment flags (as e.g. the number of threads for Julia).
  4. set a seed for Julia from R
  5. ... maybe other things I did not think about?

I would be happy to work on a first draft for some of these utility functions!

Best, Alex

s3alfisc avatar Feb 19 '22 12:02 s3alfisc

Hi Alex,

thanks, good to know that you found the package useful! Sure, you could start writing a package JuliaConnectoR.utils. Let me know about your progress and we can decide whether some of the functionality could also be integrated directly in the package. I am a bit hesitant to create too many functions inside the JuliaConnectoRpackage that do not provide really substantial things because I want to keep the interface manageable. But I could imagine that a function like setupJulia(version, installDir, manifest), which makes sure that the given Julia version and packages are installed (and if not, install them) could be a nice addition to the package. For the use by developers of packages, I would recommend to specify the dependencies via a Manifest.toml file instead of simple version numbers. Looking forward to see your suggestions.

Best wishes,

Stefan

stefan-m-lenz avatar Feb 20 '22 18:02 stefan-m-lenz

Hi Stefan! Thanks for your reply - I completely understand that you'd like to keep the package as lean as possible. I will try to set up a JuliaConnectoR.utils package and will let you know once I have something to show! Best, Alex

s3alfisc avatar Feb 23 '22 18:02 s3alfisc

Hi Stefan, I have now hacked together a super simple JuliaConnectoR.utils package. It currently consists of five functions:

  • install_julia() is a wrapper around JuliaCall::install_julia() and installs Julia from within R
  • connect_julia_r() opens the .renviron file and gives some instruction on what to do so that the JuliaConnectoR finds Julia
  • install_julia_packages() is a vectorized function that allows to install Julia packages from within R
  • check_julia_system_requirements() parses the Description file and checks if the R sessions' current Julia version and version numbers of required packages match the requirements (this function is super hacky)
  • set_julia_nthreads() gives some instructions on how to control the number of threads used in Julia from within R

Hence a workflow utilizing JuliaConnectoR.utils (for R users who have never before had any contact with Julia) could look like this:

library(JuliaConnectoR.utils)

install_julia()
connect_julia_r()
devtools::install_github("s3alfisc/fwildclusterboot")
install_julia_packages("WildBootTests.jl")
check_julia_system_requirements("fwildclusterboot")
set_julia_nthreads()

Let me know what you think!

Best, Alex

s3alfisc avatar Mar 02 '22 19:03 s3alfisc

Hi Alex, sorry for the delay but I currently have some other urgent projects going on.

  • Regarding the function check_julia_system_requirements: I would advise to use a Julia Manifest file instead of developing an additional syntax of defining Julia packages in the R description file.
  • Regarding connect_julia_r and set_julia_nthreads: This does not seem to be targeted to package developers but to end users. As an end users, I would rather find it tedious to edit my .renviron file for a package and it is hard to know about that. I rather go for good defaults and documenting possibilities for alternative configurations.

That are my thoughts so far, sorry that I am not more constructive at the moment.

stefan-m-lenz avatar Mar 08 '22 14:03 stefan-m-lenz