-
Notifications
You must be signed in to change notification settings - Fork 129
R Markdown
R Markdown document creation is supported with the following features:
- Chunk highlighting
- Chunk navigation commands (Select current chunk, go to previous/next chunks, etc.)
- Chunk execution commands (Run current chunk, run above/below chunks, etc.)
- Rmd render commands (Knit, Knit to PDF/HTML/All)
- Live preview rmd (as html)
- Create new draft from a template
By default, Rmd
files are open as Markdown documents. To enable R Markdown features, you need to associate *.Rmd
files with rmd
language. Add an entry Item *.Rmd
and Value rmd
in the VS Code settings editor:
or directly update settings.json
with the following:
{
"files.associations": {
"*.Rmd": "rmd"
}
}
pandoc is required to render R Markdown documents. Visit Installing pandoc for instructions.
You may need to restart VS Code for rmarkdown
to be able to detect pandoc
.
R Markdown documents can be knit in a VSCode-R managed background process when using the knit command. Beyond the use of a background process, this has the following features:
- Set knitr document directory
- Knit progress tracking
- Smart knitting
By default, knitr evaluates documents as though they are the root folder. For
instance, calling source
in a document will use the document's folder as the
working directory, not the document's workspace. This can be modified in
VSCode-R, so as to tell knitr if we want to evaluate from the workspace root or
the document directory.
Knit progress is tracked via a progress bar, and can be viewed in the R Markdown output stream. Progress is determined by the percentages reported in the R Markdown output stream and may not be 100% accurate.
The knit button is "smart" in that it checks the document and its workspace for
context when knitting. For instance, if a document has a knit function defined
in the YAML header, the knit button will call the custom function when knitting.
This also works for R Markdown sites, where the knit button will call
rmarkdown::render_site
instead of rmarkdown::render
.
You can live preview R Markdown documents by pressing the "Open Preview to Side" button when focused on an R Markdown document.
You can also preview a document by right-clicking it in the explorer and selecting preview.
You can also run the following code and a browser viewer will open with live rendering of the R Markdown document.
rmarkdown::run("your-rmd-document.Rmd")
When an R Markdown document is knit and rendered to an HTML file, Live Preview can be used to live preview the HTML document. It supports auto-refresh when the HTML file is updated.
You can run "R Markdown: New Draft" from the command palettes to create a new draft from an R Markdown template.
The following is a (incomplete) list of packages that provide R Markdown templates:
- Getting Started
- Installation
- Configuration
- Features
- Package development
- R Markdown
- Contributing
- FAQ