After further searching, I found a solution. Knitr has a package option that can be changed to change the behavior for processing repeating fragments by adding a number after the label, rather than with an error. See https://github.com/yihui/knitr/issues/957 .
To set this parameter, use options(knitr.duplicate.label = 'allow').
To complete the complete code for the function I wrote,
source_rmd <- function(file, local = FALSE, ...){
options(knitr.duplicate.label = 'allow')
tempR <- tempfile(tmpdir = ".", fileext = ".R")
on.exit(unlink(tempR))
knitr::purl(file, output=tempR, quiet = TRUE)
envir <- globalenv()
source(tempR, local = envir, ...)
}
source
share