Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yihui/rnotebook

R Notebook based on JSON and R Markdown (experimental)
https://github.com/yihui/rnotebook

Last synced: about 2 months ago
JSON representation

R Notebook based on JSON and R Markdown (experimental)

Awesome Lists containing this project

README

        

# rnotebook: R Notebook based on JSON and R Markdown

[![Build Status](https://travis-ci.org/yihui/rnotebook.svg)](https://travis-ci.org/yihui/rnotebook)

Traditional dynamic documents based on **knitr** are normally compiled to output documents. The separation between the source document and output document has its pros and cons. The source document is often cleaner than the output document, and easier to maintain. But some people may prefer the output to be embedded right in the source document, so they only need to maintain one single document, in which they can see both the source and output.

This package tries to define a JSON-based format for dynamic documents in R. There is no formal definition for an "R Notebook", and we use this term here because what we did in this package is similar to IPython notebooks, which is also based on JSON.

The R Notebook in this package is a JSON file, which is basically a JavaScript object with meta information, code chunks, and text chunks. Here is an example (created from `rnotebook::newnb()`):

```json
{
"frontmatter": {
"title": "An R Notebook",
"author": "Yihui Xie",
"date": "2014-12-26"
},
"body": [
{
"type": "text",
"src": "A _sample_ paragraph.",
"out": ""
},
{
"type": "code",
"src": {
"options": "tidy = TRUE",
"code": "1 + 1; x = dnorm(0)"
},
"out": ""
},
{
"type": "text",
"src": [
"We know the density of N(0, 1)",
"at 0 is `r x`."
],
"out": ""
}
]
}
```

The format should be clear if you are familiar with **knitr** documents and JSON. When compiling this document, the output is written into the `out` elements of the `body` cells instead of a new file. That is how the source and output are combined in one single file.

This package is just my proof of concept, and it may or may not be a worthwhile project in the future, given the popularity of R Markdown v2.