r markdown chunks not evaluating

I am creating a pdf from a r markdown RMD file. Part of the code outputs multiple charts in multiple chunks using a template. The inputs to the template are an alt-text string and a ggplot object. The outout of the template is a custom code chunk. These code chunks are not evaluating.

The RMD code:

Jobs by Sector

The jobs by sector charts show the distribution of employment by major economic sectors,for the current year, as defined by the Burear of Labor Statistics.

  jobssector_list <- createAlt(chartsList[[14]][['plot']],0)

  jobssector_src <- list()
  for(a in 1:length(jobssector_list)){
    jobssector_src[[a]] <- knit_expand(
      text = c("```{r jobssector-{{a}}, echo=FALSE, fig.height=4.3, fig.width=7, fig.align='center', results='asis', fig.alt='{{b}}'}",
               "print(jobssector_list[[{{a}}]][[2]])",
               "```"
               ),
      a = a, b= unlist(jobssector_list[[a]][[1]]))
  }

    
jobssector_child <- knit_child(text =  unlist(jobssector_src), quiet = TRUE)

cat(jobssector_child)

The PDF output:

Jobs by Sector
The jobs by sector charts show the distribution of employment by major economic sectors,for the current year, as defined by the Burear of Labor Statistics.
{r jobssector-1, echo=FALSE, fig.height=4.3, fig.width=7, fig.align='center', results='asis', fig.alt='Jobs by Sector: Adams County 2024'} print(jobssector_list[[1]][[2]])
{r jobssector-2, echo=FALSE, fig.height=4.3, fig.width=7, fig.align='center', results='asis', fig.alt='Jobs by Sector: Colorado 2024'} print(jobssector_list[[2]][[2]])

The chunks created by the template are correct, and the objects to be output exist, but it doesn't evaluate. This code is operating elsewhere in my RMD file.
I'd appreciate any suggestions about how to resolve this.
TIA
AB

1 Like