Development Update: R package get RStudio integration and SQL execution context


#1

One of the things we’ve been working on lately is the Stencila R package. Specifically, we’ve added new functionality that allows Stencila to better fit into the existing workflow of researchers who use R and RStudio. You can get these new features by installing the develop branch of the package:

devtools::install_github("stencila/r", ref="develop")

Use Stencila from with R or RStudio

The Stencila Desktop is a great way to use Stencila. But some users find it off putting having to download and install a new app. And although Stencila Desktop installation works fine most of the time there are always edge cases where is fails.

More importantly, people are more likely to try something if it integrates well into their existing workflow and tool set. Many R users use R Studio and try out new packages using install.packages(...) at the console, or the “Install Packages” menu item.

We wanted to give these users the same document editor as in the Stencila Desktop. So now, R users can open a Markdown or RMarkdown document in Stencila using the new open function:

stencila:::open('~/stencila/source/examples/mtcars/main.md')

Or, using the new"“Open in Stencila” RStudio addin:

When you do either of those things, the Stencila R package opens browser window and renders the document. In the browser you can edit the document, save it (Ctl+S) and the document’s source file get’s updated. Alternatively, edit the document source file in RStudio, refresh the browser window and the UI gets updated.

How does it work? Lets look at that URL: http://open.stenci.la/?peers=http://127.0.0.1:2000&address=~/stencila/source/examples/mtcars/main.md

  • At http://open.stenci.la/ we have deployed the same Javascript and CSS which is in the Stencila Desktop.
  • peers=http://127.0.0.1:2000 tells that Javascript to connect to the Stencila Host running in your R Session
  • address=~/stencila/source/examples/mtcars/main.md tells that Javascript to ask the Stencila Host to read/write to/from that file on you local disk.

Eventually we’ll bundle the Javascript and CSS in the R package so that this will work off line.

Currently, RStudio is based on an old version of Chromium and doesn’t support some of the newer Javascript syntax - so we’ll also work on creating a bundle that is compatible with RStudio so that you don’t need to open an external browser wndow.

More easily mix SQL and R code in a document

Up till now the only thing that the R package has provided is a RContext - an execution context that allows you to execute R code cells from within your Stencila Documents. We’ve now added an SqliteContext which allows you to have SQL code in you documents as well. There was already an SqliteContext in the Python package. But now you don’t need to install the Python package separately.