Coder Social home page Coder Social logo

ipyrmd's Introduction

ipyrmd

Convert between IPython/Jupyter notebooks and R Markdown documents

This script provides conversion in both directions between the IPython notebook format (JSON with separate markdown and code) and the R Markdown format (markdown text with annotated code blocks). Conversion to and from plain R files with markdown embedded in knitr-style comments (#' markdown) is also supported.

It only really makes sense to use it with IPython notebooks using the IPython R kernel, but will work with any type of code if you insist.

Conversion should produce useful output, but is not completely lossless:

  • Inline code blocks in R Markdown (r somecode) are currently ignored (they remain as markdown text). Inserting code blocks for them would be a possible extension but since the main use for such blocks is to display an output value I assume ignoring them should not usually change program flow.
  • The YAML header used in R Markdown does not have a functional equivalent in IPython. The contents of the header are stored in the IPython notebook metadata dictionary (as Rmd_header) for round-trip conversion, but are not otherwise used.
  • Chunk options for R Markdown ( ```{r, foo=bar}) also do not (currently) have any functional equivalent in the IPython notebook. The option string (as text) is stored in the cell metadata (as Rmd_chunk_options) for round-trip conversion.
  • Since whitespace is significant in markdown, we attempt to maintain blank lines within code and markdown blocks, but the boundaries between code and markdown may not be exactly reproduced (you may get extra blank lines).
  • The IPython notebook may contain both text and rich output, but there is no way to keep this for R Markdown - you will need to re-knit the document.

Usage

python3, nbformat and pyyaml are required.

ipyrmd [--to R|Rmd|ipynb] [--from R|Rmd|ipynb] [-y] [-o outfile] infile

By default the output filename and mode of conversion is determined from the input filename. Notebooks are converted by default to RMarkdown unless you specify R output.

Install

Download the archive, extract it then run python3 setup.py install --user. This should install the ipyrmd script in your local bin directory (probably ~/.local/bin).

pip users could install it via pip3 install --user git+https://github.com/chronitis/ipyrmd.

TODO

  • Options for how to handle inline R blocks
  • Consider using nbconvert machinery for ipynb -> Rmd conversion
  • Consider whether any chunk options can be emulated with IRdisplay calls
  • Check IPython API compatibility between IPython and Jupyter
  • De-duplicate code between R and Rmd methods

History

  • 0.1 (2015-05-27) Initial release
  • 0.2 (2015-05-29) Re-structure as a python library providing script ipyrmd
  • 0.3 (2015-06-09) Add support for R files with markdown embedded in #' comments

ipyrmd's People

Contributors

chronitis avatar randy3k avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.