knitr icon indicating copy to clipboard operation
knitr copied to clipboard

Support in-chunk options syntax for `knitr::purl()`

Open cderv opened this issue 3 years ago • 2 comments

With the new chunk options syntax in Quarto and multiline we should see how using purl (knitr::purl(), hook_purl() and purl = TRUE) should retrieve the params correctly when documentation = 1L the default

From @andrewpbray in https://github.com/quarto-dev/quarto-cli/discussions/1773#discussioncomment-3514864

Example

---
title: "Untitled"
format: html
keep-md: true
---

# Head 

```{r eval = TRUE}
1 + 1
```

# Head 2 

```{r}
#| eval = TRUE
2 + 2
```

# Head 3

```{r}
#| eval: true
3 + 3
```

Running knitr::purl("test.qmd") will output this R file

## ----eval = TRUE----------------------------------------------------------------------------------------------------------------------------------------------
1 + 1


## -------------------------------------------------------------------------------------------------------------------------------------------------------------
2 + 2


## -------------------------------------------------------------------------------------------------------------------------------------------------------------
3 + 3

Same with using knitr::hook_purl()

---
title: "Untitled"
format: html
keep-md: true
---

```{r}
knitr::knit_hooks$set(purl = knitr::hook_purl)
knitr::opts_chunk$set(purl = TRUE)
```

# Head 

```{r eval = TRUE}
1 + 1
```

# Head 2 

```{r}
#| eval = TRUE
2 + 2
```

# Head 3

```{r}
#| eval: true
3 + 3
```

Leading to this script

## ----r------------------------------------------------------------------------
knitr::knit_hooks$set(purl = knitr::hook_purl)
knitr::opts_chunk$set(purl = TRUE)

## ----r eval = TRUE------------------------------------------------------------
1 + 1

## ----r------------------------------------------------------------------------
2 + 2

## ----r------------------------------------------------------------------------
3 + 3

cderv avatar Aug 31 '22 13:08 cderv

Yes, we should support it. Please feel free to give it a try.

yihui avatar Sep 07 '22 21:09 yihui

Related Quarto discussion about purl() within quarto (https://github.com/quarto-dev/quarto-cli/issues/389) - just for reference

cderv avatar Sep 16 '22 13:09 cderv

Note to us: Might be better to preserve the original comments and not translate the YAML values at all.

rich-iannone avatar Dec 20 '22 16:12 rich-iannone

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

github-actions[bot] avatar Jul 12 '23 05:07 github-actions[bot]