The RStudio IDE is the flagship of a comprehensive RStudio ecosystem.
R Notebooks are the most basic type of RMarkdown document. They are the RStudio equivalent to Jupyter Notebooks. As described by RStudio:
An R Notebook is an R Markdown document with chunks that can be executed independently and interactively, with output visible immediately beneath the input.
Any R Markdown document can be used as a Notebook, and all R Notebooks can be rendered to other R Markdown document types.
The RStudio menu item File -> New File -> R Notebook creates a new RStudio Notebook containing instructions on how to use an R Notebook.
---
title: "R Notebook"
output:
html_notebook
---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Cmd+Shift+Enter*.
```
{r}
plot(cars)
```
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Cmd+Option+I*.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Cmd+Shift+K* to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
For more information see RStudio Notebook.
An R Notebook HTML file is a special type of R Notebook.
It is an HTML file that uses the .nb.html
extension and it enables:
The html_notebook
output format is specified in the YAML metadata:
title: "my_document_title"
output:
html_notebook
With the _yaml
file written this way, the command rmarkdown::render()
will create an .nb.html
R Notebook HTML Format file.
For more information, see Details of the R Notebook HTML Format.
Note: The RStudio instructions show an incorrect YAML
header. You must use the _yaml
format shown above or RStudio will throw an error and not compile.
R Markdown documents are fully reproducible. They use a productive notebook interface to weave together narrative text and code to produce elegantly-formatted output from multiple languages including R, Python, and SQL.
— RStudio RMarkdown
RMarkdown documents are the default RStudio document. They are plain-text files with the .Rmd
extension and can be used to generate many different types of output. The main ones are:
.html
.pdf
.docx
In addition to the standard output formats (above), RMarkdown documents can generate output in many other formats, via the pandoc conversion engine.
Beamer, HTML5 slides, Tufte-style handouts, books, dashboards, interactive documents, scientific articles, and websites.
RStudio maintains a gallery of examples of the many uses of RMarkdown.
RMarkdown uses the knitr report generation package to output to the different file formats.
The knitr
package enables integration of R code into LaTeX, LyX, HTML, Markdown, AsciiDoc, and reStructuredText documents. It can execute code chunks in a variety of languages via knitr Language Engines, including for:
To process a code chunk using an alternate language engine simply use the name of the engine in place of {r}
in the chunk declaration, for example:
```bash
cat flights1.csv flights2.csv flights3.csv > flights.csv
```
RMarkdown code chunk processing can be controlled by including Chunk Options in the Chunk Declaration, for example:
{r, include = FALSE
} prevents code and results from appearing.
R Markdown still runs the code and the results can be used by other chunks.
{r, eval = FALSE
} prevents to code from running but it still appears. {r, echo = FALSE
} prevents code but not the results from appearing.
This is a useful way to embed figures.
{r, message = FALSE
} prevents messages generated by code from appearing.
{r, warning = FALSE
} prevents warnings generated by code from appearing.
{r, fig.cap = "..."
} adds a caption to graphical results.
The R Markdown Reference Guide (.pdf) has a list of useful options. Yihui’s knitr
options has full documentation of all knitr
code processing controls.
The RStudio installation includes pandoc, which is used for conversion between RMarkdown and the various output formats. You may have to install pandoc on your system for conversion to take place, especially for .pdf
output, which goes through an intermediate LaTeX
stage.
pandoc
can also be run from the commond line if it is installed separately. This is explained in detail in the pandoc manual.
Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.
— RStudio Shiny
RStudio’s Shiny is a Web application framework for R that takes static RMarkdown documents and Web sites to the next level.
There is no limit to building online documentation, interactive tutorials, and statistical data interfaces with these powerful R packages:
htmlwidgets
enables JavaScript visualisations and interactive components to be incorporated into R Markdown documents and Shiny web applications, as shown in this showcase and this gallery
crosstalk
wires widgets together, including linked brushing between widgets and client side filtering
shinydashboard
makes it easy to create all kinds of Web dashboards, as shown in these examples
and others:
intrval
can be used to build for example, a Web sliderWe will explore building Shiny apps in a future Tutorial.
Shiny Server makes your Shiny Web apps accessible on a local network, an Enterprise server, or on the Internet. There are two flavours of server:
Documentation is available for:
Shiny Apps can be available to an Intranet or to the Internet via:
The difference between the latter two is explained here.
bookdown
is an open-source R package that makes it really easy to creates online books and technical documents using RMarkdown.
bookdown
books open a new avenue for Web-enabled book publishing.
They are essentially responsive RMarkdown Web sites, complete with content navigation, plus the ability to display and process computer code using a wide range of programming languages, including interactive Shiny dashboards and Web apps.
bookdown
has added a few important missing features related to writing books, such as figure and table caption numbering and cross-references, and the ability to embed HTML widgets or Shiny apps.
Developed and maintained by RStudio software engineer Yihui Xie, bookdown
books can be published on bookdown.org, a free service provided by RStudio Inc. Books are available for download, and the author holds full copyright.
Fully-documented in — of course! — a bookdown
book called bookdown, the bookdown
package uses many of the same conventions as other RMarkdown document types, so conversion of any RStudio project to an online book is relatively straightforward.
A Minimal Book Example can be cloned from GitHub. It can also be downloaded as a .zip
file if you are not familiar with GitHub.
bookdown
InstallationInstallation requires the devtools R package to be first installed, after which bookdown
can be installed from its GitHub repository:
tinytex
PDF output requires some version of the LaTeX typesetting system to be installed. LaTeX is not a stand-alone typesetting program in itself, but document preparation software that runs on top of Donald E. Knuth’s TeX typesetting system.
TeX distributions usually bundle together all the parts needed for a working TeX system. LaTeX and many of the packages built on it form an important component of any modern TeX distribution.
As this is a large package consisting of many gigabytes of files that users may not wish to install, Yihui Xie wrote tinytex
, a lightweight, cross-platform, portable, and easy-to-maintain LaTeX distribution based on TeX Live.
tinytex
InstallationInstallation of tinytex
is accomplished with:
PDF output (including Beamer slides) requires a full TeX installation.
Just as WordPress changed the Web by bringing blogging to the masses, blogdown has opened a path for the more computer-savvy to create quick-loading, static blog sites using RMarkdown.
Not content with authoring bookdown
, RStudio developer Yihui Xie took the next logical step by writing the blogdown
R package.
Based on the Hugo website framework, blogdown
lets you write posts in RStudio as RMarkdown.Rmd files These are automatically converted to blog posts for uploading to a hosting service, including GitHub pages.
blogdown
It is advisable to first read Yihui Xie and Alison Presmanes Hill’s bookdown
book Creating Websites with R Markdown to become familiar with bookdown
concepts and the Hugo framework before you embark on creating your first blog site.
These links offer practical Setup hints and guidance:
blogdown
uses Hugo themes to style the look and feel of its blogs. The default theme for blogdown
is hugo-lithium, a minimal theme that offers several options, detailed in Section 2.4.1 of the blogdown
book. The base theme can be modified to suit your taste, or it can be replaced by another theme.
The Hugo web site showcases many user-contributed themes. These can be examined online and downloaded for use as-is or as a starting point for themeing.
blogdown
blog sitesblogdown
BlogsA list of R-related blogdown
blogs is kept at rbind on Github. R-blogs made with blogdown
can be viewed here.
An interesting and uncluttered example is Simply Statistics, a statistics blog by Rafa Irizarry, Roger Peng, and Jeff Leek.
Some RStudio products are open-source and free for student and personal use. Others are priced for professional or Enterprise deployment.
.Rmd
files using Pandoc Markdownbookdown
static page books