File: compile_notebook.Rd

package info (click to toggle)
r-cran-rmarkdown 2.20%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,028 kB
  • sloc: javascript: 5,656; sh: 24; makefile: 17
file content (64 lines) | stat: -rw-r--r-- 2,302 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/render.R
\name{compile_notebook}
\alias{compile_notebook}
\title{Compiling R scripts to a notebook}
\description{
R Markdown can also compile R scripts to a notebook which includes
commentary, source code, and script output. Notebooks can be compiled to any
output format including HTML, PDF, and MS Word.
}
\section{Overview}{

  To compile a notebook from an R script you simply pass the script to
  \code{\link{render}}. For example:
  \preformatted{
rmarkdown::render("analysis.R")
rmarkdown::render("analysis.R", "pdf_document")
}
  The first call to \code{\link{render}} creates an HTML document, whereas
  the second creates a PDF document.

  By default the name of the script, username, and current date and time are
  included in the header of the generated notebook. You can override this
  default behavior by including explicit metadata in a specially formatted R
  comment:
  \preformatted{
#' ---
#' title: "Crop Analysis Q3 2013"
#' author: "John Smith"
#' date: "May 3rd, 2014"
#' ---
}
}

\section{Including Markdown}{

  Note that the R comment used above to add a title, author, and date
  includes a single-quote as a special prefix character. This is a
  \pkg{roxygen2} style comment, and it's actually possible to include many
  such comments in an R script, all of which will be converted to markdown
  content within the generated notebook. For example:
  \preformatted{#' A script comment that includes **markdown** formatting.}
  Rather than displaying as an R comment in the compiled notebook any
  \pkg{roxygen2} style comment will be treated as markdown and rendered
  accordingly.
}

\section{knitr Spin}{

  Including markdown within R comments is possible because \code{\link{render}}
  calls the \code{\link[knitr:spin]{knitr spin}} function to convert the R
  script to an Rmd file. The \code{spin} function also enables you to add
   knitr
  chunk options with another special comment prefix (\code{#+}).

  Here's an example of a script that uses the various features of \code{spin}:

  \url{https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R}

  For more details on \code{knitr::spin} see the following documentation:

  \url{https://yihui.org/knitr/demo/stitch/}
}