0

Spinning the following code (by clicking compile report in Rstudio):

#+ eval = FALSE
This line should not be syntax-checked, but it is.

Returns this error:

Error in parse(text = x, keep.source = TRUE) : 
  <text>:2:6: unexpected symbol
1: #+ eval = FALSE
2: This line

Knitting the equivalent Rmd-chunk works fine:

```{r, eval = FALSE}
Using Rmd, eval=FALSE disables the syntax-check, and does not error

I was expecting that I could spin a chunk syntactically incorrect code without getting an error (https://bookdown.org/yihui/rmarkdown-cookbook/spin.html). Am I mistaken for expecting this?

Thanks.

Rasmus Larsen
  • 5,721
  • 8
  • 47
  • 79
  • 1
    Please provide a reproducible example. – Limey Jun 28 '22 at 05:57
  • Thanks. I've now clarified that it can be reproduced by clicking "compile report" in Rstudio. – Rasmus Larsen Jun 28 '22 at 06:00
  • What command is that button running? `render` or `spin`? Try spinning the document manually first. – Roman Luštrik Jun 28 '22 at 06:13
  • @RomanLuštrik Thanks. The button runs `rmarkdown::render` which calls `knitr::knit` or `knitr::spin` depending on if input is `.Rmd` or `.R` (https://rmarkdown.rstudio.com/articles_report_from_r_script.html). When I follow your suggestion and run the document using `knitr::spin`, I get the same error. – Rasmus Larsen Jun 28 '22 at 06:41
  • 2
    It's not documented, but `knitr::spin()` requires the input R script to be a valid R script ([technical detail here](https://github.com/yihui/knitr/blob/c874c171afa348e883485afcd0fb3bdff29a280d/R/spin.R#L69)). One workaround is that you quote this sentence (i.e., turn it into a string). – Yihui Xie Jun 28 '22 at 22:39

1 Answers1

0

This is not possible, but a workaround is to quote the sentence :

# Syntax checked:
2+2 
#> [1] 4

# Not syntax checked:
"
2 a 
"
#> [1] "\n2 a \n"

(source: Yihui Xie's comment above at 28jun2022)

Rasmus Larsen
  • 5,721
  • 8
  • 47
  • 79