I'm developing a package that generates author lists from tabular data for Rmarkdown and Quarto. The package allows users to append ORCID icons to authors who have an ORCID identifier.
ORCID icons are located in the inst/icons/
directory.
I'm using the following function to get the icon path:
get_icon <- function(file) {
system.file(paste0("icons/", file), package = "pkg_name")
}
I then have a function that generates the icon and hyperlink in markdown, either as pdf
or svg
depending on the output format of the document (determined by knitr::is_html_output()
).
# as pdf
[\\hspace{3.000000pt}![](/path_to_pkg/pkg_name/inst/icons/orcid.pdf){height=16px}\\hspace{3.000000pt}](https://orcid.org/0000-0000-0000-0001)
# as svg
[![](/path_to_pkg/pkg_name/inst/icons/orcid.svg){height=16px style='margin: 0 4px; vertical-align: baseline'}](https://orcid.org/0000-0000-0000-0001)
I'm wondering how I should test this with testthat
. I guess the test would do the following:
- generating a temporary
Rmd
/qmd
file - render it
- compare the generated image link to a character string containing a pre-made image link to ensure that: (1) the image link is properly formatted and (2) the icon format is correct depending on whether the document is rendered as HMTL or not.
Besides, I guess I need to test it in a temporary directory (or package?) so that the icon path doesn't use my local one (e.g. /Users/user_name/pkg_name/inst/icons
on my system). I know that withr
has some tools for this but I'm fairly new to unit tests and package development in general so I'd love to have some guidance on this one.