rrstudior-markdownknitrmacos-catalina

R Markdown won't knit; Error in parse attempt to use zero-length variable name


I'm trying to prepare an Rmarkdown file for a course. But for some reason (perhaps a very, very dumb reason) I can't seem to knit anything. Here is a very simple example of an Rmarkdown script:

    ---
    title: "big data"
    author: "CAM"
    date: "21 March 2020"
    output:
    html_document: default
    ---

    ```{r,chunk1,eval=TRUE,echo=TRUE,include=TRUE}
    seq(1,10,by=1)
    ```

This throws the error:

Error in parse(text = x, keep.source = TRUE) : 
  attempt to use zero-length variable name
Calls: <Anonymous> -> <Anonymous> -> getParseData -> parse
Execution halted

The code itself executes in the chunk, but it won't knit.

Here is my session info. (I just moved to catalina on mac, maybe there's a problem here).

R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] knitr_1.28    rmarkdown_2.1

loaded via a namespace (and not attached):
[1] compiler_3.6.3  htmltools_0.4.0 tools_3.6.3    
[4] yaml_2.2.1      Rcpp_1.0.3      xfun_0.12      
[7] digest_0.6.25   rlang_0.4.5     evaluate_0.14 

Solution

  • Found the answer. It's has to be saved as a .Rmd file, not an .R file. This is the case even if you selected your script as a Rmarkdown file within RStudio.