'rmarkdown knitting error cannot replicate NULL to a non-zero length

I have a rmarkdown which loops to render a list of other rmarkdowns:

```{r}
for(i in 0:22){
   save(i, file = "/path/to/i.RData")
   rmarkdown::render("path/to/secondRmarkdown.Rmd", output_file = paste0("/path/to/Results/Report_", i, ".html"))
}
```

Previous to this chunk, I have a pretty similar chunk in the same rmarkdown, and it loops without a problem while knitting the main one. Moreover, when I run the chunk manually, it also loops.

However, when knitting, this specific chunk gives the following error after rendering only the first rmarkdown file for i=0 (which succeeds):

# Error in rep_len(label, length(meta): cannot replicate NULL to a non-zero length

I modified the secondRmarkdown.Rmd to a simple file to make sure it wasn't something from it:

```{r}    
load(file = "/path/to/i.RData")
print(i)
```

I have Ubuntu 5.13.0-40. R version 4.2.0, Rstudio version 2022.02.2, rmarkdown version 2.14

Any idea? TIA!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source