Skip to main content

A Rmarkdown to SoS Notebook converter

Project description

Anaconda-Server Badge PyPI version Build Status

sos-rmarkdown

The RMarkdown format is a markdown format with embedded R expressions and code blocks, and is extremely popular for R users. The sos-rmarkdown module provides converters to convert Rmarkdown files to SoS notebooks using the sos converter mechanism.

Installation

You can install sos-rmarkdown and related tools (sos-notebook, papermill, sos-papermill etc) with command

pip install sos-rmarkdown

or

conda -c conda-forge sos-rmarkdown

if you are using a conda environment.

Basic Usage

You can convert a Rmd file with command

sos convert input.Rmd output.ipynb

and optionally execute the resulting notebook with option --execute

sos convert input.Rmd output.ipynb --execute

If you would like to further convert the Jupyter notebooks to HTML format, you can use commands

sos convert output.ipynb output.html --template sos-report-toc-v2

You can combine the two steps with commands such as

sos convert input.rmd output.html --execute --template sos-report-toc-v2

Features

Although there are already a number of Rmd to Jupyter converters (e.g. notedown, RMD-to-Jupyter (uses rpy2)), they lack support for some of the Rmakdown features due to limitations of the Jupyter notebook platform. Fortunately, SoS Notebook, especially its Jupyter Lab extension addresses most of the limitations and offers an almost perfect conversion from R markdown to Jupyter notebook.

The first Rmarkdown feature that is difficult to convert is its inline expressions, which are R expressions embedded in markdown texts. Jupyter cannot handle embedded expressions in its markdown cells because markdown cells are handled in its frontend and does not interact with the computing kernel. SoS Notebook addresses this problem with the use of a markdown kernel, which is essentially a markdown kernel

For example, the following Rmarkdown text

I counted `r sum(c(1,2,3))` blue cars on the highway.

is converted to a markdown cell that is evaluated in a R kernel as follows

image

The second Rmarkdown feature is its support for multiple languages, which allows it to have code blocks in a number of langauges. A Jupyter notebook with an ir kernel can only evaluate R scripts, but a SoS Notebook is able to include multiple kernels in one notebook.

For example, code blocks such as

def f(x):
  return x + 2
f(2)

and

def f(x):
  return x + 2
f(2)

are converted to cells with approprivate kernels such as

image

in a separate Python3 kernel.

The last feature that is not properly supported are options such as echo=FALSE and include=FALSE for Rmarkdown code blocks. There were no corresponding features for classic Jupyter Notebook but Jupyter Lab supports hiding of input and/or output of cells. Using these features, code blocks such as the following are converted as collapsed input and/or outputs,

arr <- rnorm(5)
cat(arr)

image

A related problem is that jupyter nbconvert does not respect the collasping status of cells and renders input and output of all cells. SoS Notebook addresses this problem by providing templates that honor the show/hide status of cells. For example, template sos-report-toc-v2 outputs all cells but hides collapsed inputs and outputs by default. The hidden content could be displayed by selecting a dropdown box to the top right corner of the document.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sos-rmarkdown-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sos_rmarkdown-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file sos-rmarkdown-0.1.0.tar.gz.

File metadata

  • Download URL: sos-rmarkdown-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for sos-rmarkdown-0.1.0.tar.gz
Algorithm Hash digest
SHA256 31030cf09bcc675b76312dd3728c35c3621246359208d0baf80958dcc4256fc0
MD5 53b188fc4b59f2fad79184d451586698
BLAKE2b-256 bae8c912d055045310039eaad6b0a36697b5396d49c8bea2cd2bff463fc009d3

See more details on using hashes here.

File details

Details for the file sos_rmarkdown-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sos_rmarkdown-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for sos_rmarkdown-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1c83d6dfb80fab8981ef405f20d3c43dc3c945eccefaee42e452fa98ce7ea29
MD5 12b715e838e89324bc6bc05991d812e9
BLAKE2b-256 0c273175c2bdf50cb5b60296a5abe0862d1477d28d035fae33d125649bb1b318

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page