8  qmd/Rmd

8.1 Loop with child (sub file)

Main-file: main.qmd

Sub-file: stateplot.qmd

Output: main.html

## Individual States

# results: asis #output raw md content 

STATE_vec <- c("AL", "AK", "AZ", ...)

#create empty list 
res <- vector("list", length = 3L)

#run loop 
for (i in 1:length(STATE_vec)) { 
  
  #run sub w/ state, save in list
  res[[i]] <- knitr::knit_child(
      "stateplot.qmd"      
    , quiet = TRUE
    , envir = environment()
    )
}

#unlist and paste together w/ a break 
cat(unlist(res), sep = '\n')
#specify which state should be used
this_STATE <- STATE_vec[i]  

### `r this_STATE`

all_data %>% 
  filter(STATE == this_STATE) %>% 
  plot_function()

Individual States

AL

AK

AZ

8.2 quarto_render()

#when bugs are fixed 
# quarto::quarto_render(input = "in.qmd", output_file = "products/output.html")

quarto::quarto_render(input = "ind.qmd", output_file = "output.html")
file.copy(from = "output.html", to = "products/output.html", overwrite = TRUE)
rm("output.html")

8.3 Output and Pathways

8.4 Style