Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new 'r.rmarkdownRender' command #3308

Merged
merged 3 commits into from
May 30, 2024
Merged

Conversation

juliasilge
Copy link
Contributor

@juliasilge juliasilge commented May 29, 2024

Intent

Addresses #1421 by adding a command to do rmarkdown::render() in a fresh R session (i.e. R terminal)

Approach

This PR adds a command that is similar to 'r.sourceCurrentFile' but checks to see if rmarkdown is installed and runs it in a new terminal.

QA Notes

We should check how this command works both with/without the Quarto extension installed. It contributes both a command to the command palette and to the "editor/title/run" bar, but only for .Rmd and not .qmd. The 'r.sourceCurrentFile' command should all still work as expected.

You can make a file saved as .Rmd such as this:

---
title: "A wonderful R Markdown document"
output:
  html_document:
    math_method: katex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

Here is some math:

$1 + 1$

You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Copy link
Contributor Author

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not provide support for previewing any R Markdown, only doing rmarkdown::render().

Comment on lines +467 to +472
},
{
"command": "r.rmarkdownRender",
"icon": "$(play)",
"title": "%r.command.rmarkdownRender.title%",
"when": "(resourceExtname == '.rmd' || resourceExtname == '.Rmd') && !isInDiffEditor"
Copy link
Contributor Author

@juliasilge juliasilge May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Quarto extension is installed, you see this in the "editor/title/run" spot:

Screenshot 2024-05-29 at 7 42 19 PM

If the Quarto extension is not installed, you will see a play button that only has the R Markdown option.

Comment on lines +381 to +387
{
"category": "R",
"command": "r.rmarkdownRender",
"icon": "$(play)",
"title": "%r.command.rmarkdownRender.title%",
"when": "resourceExtname == '.rmd' || resourceExtname == '.Rmd'"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the Quarto extension installed, you see these options in the command palette:

Screenshot 2024-05-29 at 3 25 32 PM

@juliasilge juliasilge marked this pull request as ready for review May 30, 2024 02:08
@juliasilge juliasilge requested a review from jmcphers May 30, 2024 02:09
@juliasilge juliasilge merged commit f83be6d into main May 30, 2024
1 check passed
@juliasilge juliasilge deleted the rmarkdown-render-command branch May 30, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants