newnb: Create a new notebook file

Description Usage Arguments Value Examples

View source: R/rnotebook.R

Description

Create a notebook file based on the metadata (e.g.,title and author, etc) and the content.

Usage

1
2
3
newnb(file = tempfile("rnotebook", ".", ".Rnb"), title = getOption("rnotebook.title", 
    "An R Notebook"), author = getOption("rnotebook.author"), date = Sys.Date(), 
    ..., body)

Arguments

file

the notebook filename

title

the title of the notebook

author

the author of the notebook

date

the date for the notebook

...

other metadata for the notebook

body

the body of the notebook; a default list of content is used if not provided, otherwise it should be a list of sub-lists, with each sub-list being a list of elements type (text or code), src (source), and out (output); for type = 'code', src is a list of two elements options (chunk options) and code (source code)

Value

The notebook filename (a temporary file by default, with the prefix rnotebook). The metadata and content are written to the file as a JSON string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
f = rnotebook::newnb()
rnotebook::refresh(f)  # compile the notebook
file.show(f)

f2 = rnotebook::newnb('foo-test.Rnb', author = 'R. A. Fisher', body = list(
  list(type = 'text', src = 'Hello **world**.', out = NULL),
  list(type = 'code', src = list(
    options = '', code = 'fisher.test(matrix(c(3, 1, 1, 3), 2))'
  ), out = '')
))
file.show(f2)
rnotebook::refresh(f2)

# serve notebooks using the servr package (click the .Rnb filenames)
if (!requireNamespace('servr') || packageVersion('servr') < '0.1.10')
  install.packages('servr', repos = 'http://yihui.name/xran')
if (interactive()) servr::notebook()

yihui/rnotebook documentation built on May 28, 2017, 9:39 a.m.