Skip to content

This extension provides a few snippets and key bindings for common tasks in .Rmd documents, such as inserting code chunks and including images using knitr::include_graphics(). Additionally, it aims to provide some helper functions for Bookdown and Blogdown.

License

Notifications You must be signed in to change notification settings

TianyiShi2001/rmarkdown-vscode

Repository files navigation

R Markdown All-in-One for VS Code

Number of Installs Ratings Say thanks

This extension provides a few snippets and key bindings for common tasks in .Rmd documents, such as inserting code chunks and including images using knitr::include_graphics().

Additionally, it aims to provide some helper functions for Bookdown and Blogdown.

This project is at its very early stage of development. Contributions are welcome!

Table of Contents

Video Demos

If you prefer reading text, jump to RMarkdown-Specific Features, Blogdown-Specific Features, Bookdown-Specific Features, or Other Markdown Features.

Code Chunk

As you would do in RStudio, you can use Ctrl/Cmd+Alt+I to insert a code chunk (alternatively, you can write \code to trigger this snippet). The language defaults to R, but you can also use many other langauges supported by knitr.

insert code chunk demo

The first tab stop allows you to configure this code chunk (language, label, eval, echo, etc.), and the second one is where you write the code. The third tab stop inserts a blank line between after the code chunk, which is required by the .Rmd format.

Include Graphics

In the world of R Markdown, knitr::include_graphics() is the preferred way of inserting images over Markdown's native ![]() syntax. If you don't know it, you should. Its syntax, however, is rather verbose.

With VSCode RMarkdown extension, you use the \fig snippet.

include graphics demo

Knitting

Use Ctrl/Cmd+Shift+K to knit the document with options specified in the YAML header, like in RStudio.

knitting demo

RMarkdown-Specific Features

Keyboard Shortcuts:

Description Windows/Linux Mac Note
Insert Code Chunk Ctrl+Alt+I Cmd+Option+I The first tab stop allows for easy configuration, the second for the actual code
Knit Ctrl+Shift+K Cmd+Shift+K Knit current .Rmd document with options specified in the YAML frontmatter

Snippets

Cross-referencing

\ref or \@ref: general cross-reference; inserts \@ref($1) \refsec or \@sec: section cross-reference; inserts Section \@ref($1) \reffig or \@fig: figure cross-reference; inserts Figure \@ref(fig:$1) \reftab or \@tab: table cross-reference; inserts Table \@ref(tab:$1)

Chunks

\code: insert a code chunk \fig: insert a chunk using knitr::include_graphics() to include an image; hit tabs to conviniently fill out label, fig.cap and out.width.

Bookdown-Specific Features

Before you can use blogdown-specific features, you need to first open the directory of your bookdown project. The easiest way is to use RStudio's 'New Project'.

Serve Book

  1. In the command palette (Ctrl/Cmd+Shift+P), search for serve book
  2. Execute Blogdown: Serve Site
  3. Click the link in the output to view your book
  4. You are redirected to your new site (not implemented yet)!

Blogdown-Specific Features

Before you can use blogdown-specific features, you need to first open the directory of your blogdown project. The easiest way is to use RStudio's 'New Project'.

New Post

  1. In the command palette (Ctrl/Cmd+Shift+P), search for new post
  2. Execute Blogdown: New Post, then fill out basic information (title, author, category, archetype)
    • You can set the default author in the settings Ctrl/Cmd + ,
  3. You are redirected to your new post!

blogdown new post demo

Serve Site

  1. In the command palette (Ctrl/Cmd+Shift+P), search for serve site
  2. Execute Blogdown: Serve Site
  3. Click the link in the output to view your blog
  4. You are redirected to your new site (not implemented yet)!

Other Markdown Features

Syntax Highlighting

Mostly adapted from microsoft/vscode and yzhang-gh/vscode-markdown.

Table Formatter

table formatter demo

Keyboard Shortcuts

Mostly adapted from yzhang-gh/vscode-markdown.

Description Windows/Linux Mac Note
toggle bold Ctrl + B Cmd + B
toggle italics Ctrl + I Cmd + I

TODO

  • general
    • adapt and modify existing markdown support extensions preview HTML/PDF
    • insert tables (with labels and captions)
    • citation autocompletion
    • run code?
    • Navigation bar
  • bookdown
  • blogdown
    • to be consistent with RStudio's plugin, 'new post' should produce <date>-<slugified-title>.Rmd?

Change Log

See CHANGELOG.md

Required packages:

(certain command may provide no response or give out errors when the packages are not installed)

rmarkdown
bookdown
servr

About

This extension provides a few snippets and key bindings for common tasks in .Rmd documents, such as inserting code chunks and including images using knitr::include_graphics(). Additionally, it aims to provide some helper functions for Bookdown and Blogdown.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published