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 support for # %% for chunk demarcation in knitr::spin #2307

Merged
merged 3 commits into from
Nov 27, 2023
Merged

Add support for # %% for chunk demarcation in knitr::spin #2307

merged 3 commits into from
Nov 27, 2023

Conversation

kylebutts
Copy link
Contributor

@kylebutts kylebutts commented Nov 26, 2023

Hi,

The R VSCode extension has nice support for inline code chunks for R scripts using the # %% comment to separate code chunks. This small change would integrate with this and allow a seamless .R notebook script to report pipeline

This will also help with quarto-dev/quarto-cli#6660 allowing to render .R scripts with quarto
https://quarto.org/docs/prerelease/1.4/script.html

Running knitr::spin("test.R", format = ".qmd) on this

#'---
#'title: "test"
#'---

# %% setup
#| message = FALSE,
#| warning = FALSE
library(tidyverse)

v = seq(-pi, pi, 0.01)
data = data.frame(
  x = v, y = sin(v)
)

# %% 
ggplot() + 
  geom_point(
    aes(x = x, y = y),
    data = data
  )

produces a valid qmd document:

---
title: "test"
---

```{r setup}
#| message = FALSE,
#| warning = FALSE
library(tidyverse)

v = seq(-pi, pi, 0.01)
data = data.frame(
  x = v, y = sin(v)
)

```
```{r}
ggplot() + 
  geom_point(
    aes(x = x, y = y),
    data = data
  )
```

@CLAassistant
Copy link

CLAassistant commented Nov 26, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

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

Looks great! Could you add a news bullet to https://github.com/yihui/knitr/blob/master/NEWS.md#new-features? Then I'll merge this PR. Thanks!

@yihui yihui merged commit a51a7a0 into yihui:master Nov 27, 2023
1 check passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants