Site icon R-bloggers

webrcli & spidyr: What’s new

[This article was first published on Colin Fay, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Find all my posts about webR here.

Note: the first post of this series explaining roughly what webR is, I won’t introduce it again here.

In this blogpost, you’ll find some updates about some recent changes made in webrcli & spidyr.

What webrcli & spidy wants to achieve

In a nutshell, the goal of webrcli & spidyr is to provide an interface for bringing your R functions inside a NodeJS runtime.

Think of it as something that wants to achieve the following interation:

An important note

With webR & the tools described below, there is no R session running while the NodeJS app is running. spidyr imports an R function converted to a native JS. rfuns.hello_world does not call an R session running somewhere else.

That also means that if you build a container containing the app, you don’t need to install R in it. It’s a NodeJS app.

Below are some updates recently made to both webrcli & spidyr.

Making the template code smaller

When drafting the first code of webrcli & spidyr, I focused on providing a minimal template for an index.js loading your R functions, contained in a subdirectory inside your node project.

This worked, but might have been a bit complex to grasp. Provided you don’t change the default names of the folders (in that case you’ll need to modify the default parameters), the new default index.js look like this:

const {
  initSpidyr,
  mountLocalPackage
} = require('spidyr');

(async () => {

  await initSpidyr()

  const rfuns = await mountLocalPackage("./rfuns");

  const hw = await rfuns.hello_world()

  console.log(hw.values);

  console.log("✅ Everything is ready!");
})();

This minimal template makes it easier to read and understand what the code does. Note that you’ll get this template if you run webrcli init myproject.

Let’s decompose what this code does :

new Library() is now library()

Calling a package is now const spongebob = library("spongebob") instead of the previous approach which was const spongebob = new Library("spongebob");await spongebob.load(globalThis.webR);

Better installation from package.json & DESCRIPTION

The previous version of webrcli did not stored nor re-installed the R package installed in the project, meaning that if you git cloned a project, you had to guess what R packages to re-install.

Now, a project initiated with webrcli will store all the packages installed with webrcli install inside the package.json file. Then, when running the npm install command, the R packages will also be redownloaded.

You can also installed a series of packages based on a DESCRIPTION file with webrcli installFromDesc.

Other tools

Workflow summary

Please do give it a shot

I think I’ve been the only user for now 😅, so please do try these and let me know what you think.

Future works

Here are what I plan on working in the upcoming weeks:

To leave a comment for the author, please follow the link and comment on their blog: Colin Fay.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version