FredHutch / VISCtemplates

Tools for writing reproducible reports at VISC
Other
6 stars 2 forks source link

package-loading-and-options chunk generates error when run interactively #242

Open mayerbry opened 1 month ago

mayerbry commented 1 month ago

the following code

# fig.align argument is not supported in Word (align in template docx)
if (knitr::opts_knit$get('rmarkdown.pandoc.to') == 'latex'){
  opts_chunk$set(fig.align = "center")
}

produces the error Error in if (knitr::opts_knit$get("rmarkdown.pandoc.to") == "latex") { : argument is of length zero when run interactively

> packageVersion("knitr")
[1] ‘1.48’
> packageVersion("VISCtemplates")
[1] ‘1.3.2’
mayerbry commented 1 month ago

solution: replace knitr::opts_knit$get("rmarkdown.pandoc.to") with get_output_type() which handles a null return

slager commented 1 month ago

Do you encounter any problems with using insert_break(), insert_references_section_header(), or insert_ref() when running interactively? I ask because these also directly access knitr::opts_knit$get("rmarkdown.pandoc.to"). It looks like insert_ref() already has some NULL-handling. If we're wanting to support running the Rmds interactively, this might be a good time to make any needed fixes there as well.