rmarkdown icon indicating copy to clipboard operation
rmarkdown copied to clipboard

Commented-out inline R-code can throw errors

Open cjvanlissa opened this issue 2 years ago • 1 comments

As illustrated in this reproducible example, commented-out inline R-code can still throw errors:

---
title: "Untitled"
author: "Caspar J. van Lissa"
date: '2022-06-23'
output: html_document
---

```{r}
a <- "bla"
```

This works `r a`

```{r eval = FALSE}
b <- "bla"
```

<!-- This does not work `r b` -->

<!-- ```{r eval = FALSE} -->
<!-- c <- "bla" -->
<!-- ``` -->
<!-- This also does not work `r c` -->

R version 4.1.2 (2021-11-01) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042), RStudio 2022.2.3.492

Locale: LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252

Package version: base64enc_0.1.3 bslib_0.3.1 digest_0.6.29 evaluate_0.14 fastmap_1.1.0 fs_1.5.1
glue_1.5.1 graphics_4.1.2 grDevices_4.1.2 highr_0.9 htmltools_0.5.2 jquerylib_0.1.4 jsonlite_1.8.0 knitr_1.36 magrittr_2.0.1 methods_4.1.2 R6_2.5.1 rappdirs_0.3.3
rlang_1.0.2 rmarkdown_2.14.3 sass_0.4.0 stats_4.1.2 stringi_1.7.6 stringr_1.4.0
tinytex_0.35 tools_4.1.2 utils_4.1.2 xfun_0.28 yaml_2.2.1

Pandoc version: 2.17.1.1

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • [ V] formatted your issue so it is easier for us to read?

  • [ V] included a minimal, self-contained, and reproducible example?

  • [ V] pasted the output from xfun::session_info('rmarkdown') in your issue?

  • [ ~] upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • [V ] installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown")?

cjvanlissa avatar Jun 23 '22 17:06 cjvanlissa

This is related to an old issue https://github.com/rstudio/rmarkdown/issues/974

there is now a specific comment engine to achieve this - knitr does not know how to parse HTML comment, to it will still find inline R code inside HTML comment and evaluate it.

See https://yihui.org/en/2022/01/knitr-news/#the-new-engines-comment-verbatim-and-embed

---
title: "Untitled"
author: "Caspar J. van Lissa"
date: '2022-06-23'
output: html_document
---

```{r}
a <- "bla"
```

This works `r a`

```{r eval = FALSE}
b <- "bla"
```

````{comment}
This does not work `r b`

```{r eval = FALSE}
c <- "bla"
```
This also does not work `r c`
```` 

cderv avatar Jun 23 '22 17:06 cderv