Error in parse_block(g[-1], g[1], params.src): duplicate label 'unnamed-chunk-1
Solution 1
There are 2 situations:
- You could have a duplicate chunk name
- You could have copied and pasted the same code over. If so do the following:
options(knitr.duplicate.label = "allow")
https://bookdown.org/yihui/rmarkdown-cookbook/duplicate-label.html
Solution 2
It looks like there is an explanation and solution to this exact problem give here https://bookdown.org/yihui/rmarkdown-cookbook/duplicate-label.html
options(knitr.duplicate.label = "allow")
I've tried it on my own system, when faced with the same problem, and it was resolved.
Related videos on Youtube
Jan Pips
Updated on June 04, 2022Comments
-
Jan Pips almost 2 years
There is something strange with this error. Sometimes the same rmd file with r chunks runs without problems and knitr assigns sequential number after the 'unnamed-chunk-' but sometimes knitr reports error.
I can't find any way to identify under what circumstances the process runs smoothly and when it generates error. All r chunks within rmd file are without the name/label.
Below there is the log of command in case everything is going smoothly and the not labels chunks are given sequential number
outfile = c(outfile, knit("File1.rmd")) processing file: File1.Rmd |..... | 8% ordinary text without R code |........... | 17% label: unnamed-chunk-1 (with options) List of 1 $ echo: logi FALSE |................ | 25% inline R code fragments |...................... | 33% label: unnamed-chunk-2 (with options) List of 4 $ echo : logi FALSE $ connection: symbol db.conn $ output.var: chr "db.data" $ engine : chr "sql" |........................... | 42% ordinary text without R code |................................ | 50% label: unnamed-chunk-3 (with options) List of 1 $ echo: logi FALSE |...................................... | 58% ordinary text without R code |........................................... | 67% label: unnamed-chunk-4 (with options) List of 1 $ echo: logi FALSE |................................................. | 75% ordinary text without R code |...................................................... | 83% label: unnamed-chunk-5 (with options) List of 1 $ echo: logi FALSE |............................................................ | 92% ordinary text without R code |.................................................................| 100% label: unnamed-chunk-6 (with options) List of 1 $ echo: logi FALSE output file: Test_DSN-ARAMIS-01.md > outfile = c(outfile, knit_child("File2.Rmd")) processing file: File2.Rmd |............. | 8% ordinary text without R code |......................... | 17% label: unnamed-chunk-1 (with options) List of 1 $ echo: logi FALSE |...................................... | 25% inline R code fragments |.................................................. | 33% label: unnamed-chunk-2 (with options) List of 4 $ echo : logi FALSE $ connection: symbol db.conn $ output.var: chr "db.data" $ engine : chr "sql" |............................................................... | 42% ordinary text without R code |............................................................................ | 50% label: unnamed-chunk-3 (with options) List of 1 $ echo: logi FALSE |........................................................................................ | 58% ordinary text without R code |..................................................................................................... | 67% label: unnamed-chunk-4 (with options) List of 1 $ echo: logi FALSE |................................................................................................................. | 75% ordinary text without R code |.............................................................................................................................. | 83% label: unnamed-chunk-5 (with options) List of 1 $ echo: logi FALSE |.......................................................................................................................................... | 92% ordinary text without R code |.......................................................................................................................................................| 100% label: unnamed-chunk-6 (with options) List of 1 $ echo: logi FALSE
and the second execution of the same files gives the following output when processing second file
> outfile = c(outfile, knit_child("File2.Rmd")) processing file: File2.Rmd Error in parse_block(g[-1], g[1], params.src) : duplicate label 'unnamed-chunk-1'
-
Prevost over 5 yearsCan you add unique names to each chunk?
-
Jan Pips over 5 yearsYes I can and that solves the error but not solves the issue. Adding unique labels to a chunk is workable for a dozen of files with say less than 10 chunks within each file. But doing that for 60 files is a pain in the ass unless there is the way to generate randomly the chunk labels which I am not aware of.
-
Prevost over 5 yearsGood point. I work in
.rnw
files. For printing auto-genreatedxtables
I create a list ofprint(xtable(x))
objects each with their own auto-genreated caption and runlapply(x, cat)
orfor (i in 1:length(x)){}. For multiple auto-generated figures, I also put those into a list and then use
invisible(lapply(x,print))` to print all the figures. The caption is the same for all the figures. I differentiate between the figures by applying a descriptive legend title. You would need a chunk for each type of plot though.
-