Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mayerbry opened this issue Sep 9, 2024 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@mayerbry
Copy link
Contributor

mayerbry commented Sep 9, 2024

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
Copy link
Contributor Author

mayerbry commented Sep 9, 2024

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

@slager
Copy link
Contributor

slager commented Sep 26, 2024

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.

@slager slager added the bug Something isn't working label Jan 7, 2025
@mayerbry
Copy link
Contributor Author

mayerbry commented Jan 8, 2025

All of those functions run fine interactively for me. I believe the problem is specifically that knitr::opts_knit$get("rmarkdown.pandoc.to") returns NULL so when it's compared directly to something it returns a length 0 vector rather than a T/F and that was the source of the error within an if().

@slager slager closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants