rmarkdown:render in for loop throws ! Undefined control sequence. \@sharp ->\makecell

I created a R markdown document that takes a report ID number as a parameter and then uses that ID to query a database to pull all the information that goes into the report.
The report uses these libraries: "rmarkdown", "readxl", "dplyr", "Rblpapi", "tidyr", "lubridate", "stringr","knitr", "kableExtra", "RCurl", "XML", "RMySQL" and "webshot"

The report worked fine when I ran it by clicking the knit button in RStudio with a hardcoded report ID#. When I moved to a for loop and calling rmarkdown::render with the Rmd file as a parameter the report will only run once and then throws this error for an add_header_above() header.

! Undefined control sequence.
@sharp ->\makecell
[c]{A title header that spans 5 columns}

If I restart R and run it it will run 1 report again and then fail. I made sure I only load packages once by checking if they are already loaded using (.packages()). I need to make a few dozen of these reports so calling render from the for loop needs to work.

These are the parameters I am passing to the render function:

thisValue = rmarkdown::render("AReport.Rmd",
params = list(reportID = thisID),
output_format = "pdf_document")

Where is add_header_above() ? Is it from one of the *down package ?

Are you not changing the output document name ?

This seems related to a missing CTAN package which contains the command \makecell. What tool are you using for making your table ?

You could also try to render the file in a new session each time so that the rendering happens in a clean new environment

callr::r(function(ID) {
  rmarkdown::render("AReport.Rmd",
  params = list(reportID = ID),
  output_format = "pdf_document", 
  output_file = paste0("report-", ID, ".pdf"))
}, list(ID = thisID))

Something like that (I don't have an example to try on.