Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rmarkdown error "attempt to use zero-length variable name"

Tags:

r

r-markdown

When i generate a new rmarkdown file (or open existing rmarkdown-files) and try to run a rmarkdown chunk, i get this error: "Error: attempt to use zero-length variable name". I have Win10 and did a fresh install of R and Rstudio yesterday. What did i miss? Where does this error come from?

```{r cars}
summary(cars)
```

```{r cars} Error: attempt to use zero-length variable name

enter image description here

like image 351
SEMson Avatar asked Sep 12 '17 08:09

SEMson


People also ask

What does attempt to use zero-length variable name mean in R?

Description of the problem The “error: attempt to use zero-length variable name” error message occurs when you are using the global environment as a rmd editor, and you try to run code that has backtick characters. These are disallowed characters, and their presence causes a problem.

How do you enter R code in Rmarkdown?

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS).


1 Answers

Putting this as an answer for visibility: this happens if you try to run by selecting all in the Rmd and pressing enter like you would with a normal R script. RStudio tries to run this all as R code, including the markdown parts, leading to the errors you saw.

You can avoid this by running an individual chunk by clicking the green play button or by selecting one of the run options in the dropdown at the top of the Rmd editor.

like image 105
Donovan192 Avatar answered Oct 04 '22 21:10

Donovan192