pkgdown icon indicating copy to clipboard operation
pkgdown copied to clipboard

Issue with DOI in reference docs added through Rd macros

Open rickhelmus opened this issue 3 years ago • 7 comments

Hi all,

I am using a small macro to semi-automatically add package citations of dependent packages to the reference documentation of my package. However, with the latest pkgdown (2.0.1) this may result in the following error:

Error in read_xml.raw(charToRaw(enc2utf8(x)), "UTF-8", ..., as_html = as_html,  : 
  Name doi:10.18637 is not XML Namespace compliant [202]                                
In addition: There were 15 warnings (use warnings() to see them) 

After a while I could track it down to the first citation of the Rcpp package. I can reproduce it by adding the following line manually in the Rd file:

\Sexpr[results=text,echo=FALSE,strip.white=FALSE]{print('<doi:10.18637/jss.v040.i08>')}

If I add the DOI text directly without macro I don't get any errors.

EDIT: I also tried versions 2.0.2 and 2.0.0 without success, but v1.6.1 seems to work. EDIT2: Actually, v1.6.1 doesn't correctly work either: the doi is simply stripped from the output...

Thanks, Rick

rickhelmus avatar Jan 20 '22 16:01 rickhelmus

Two (naive) questions:

Could you show what a help page that shows that DOI looks like? (a help page not in pkgdown).

Did you choose this printing format so it'd get autolinked? Why not directly output a link (that might not look like a problematic XML tag)?

maelle avatar Jan 21 '22 13:01 maelle

Hi, thanks for your reply.

Example page rendered from R:

image

The macro uses the textVersion of the citation, which now happens to have these 'tags'.

I guess in the worst case the Rd macro could strip the tags out, but I wander if there is a more generic and future proof solution.

rickhelmus avatar Jan 21 '22 14:01 rickhelmus

I think you need to escape the angle brackets, but I'm not sure which escapes would work. "&lt;" for "<" would be fine for HTML rendering, but it wouldn't work in PDF. There are conditionals that can be used in the macros to control that, or your macro could call an R function that determined the target format before producing the text to include.

dmurdoch avatar Jan 21 '22 14:01 dmurdoch

I'm having the same error message with a different use case.

My package mentions <doi:10.5281/zenodo.1485309> in the Description: field of DESCRIPTION. I have a function that updates inst/CITATION based on the content of DESCRIPTION. The content of Description: field of DESCRIPTION becomes the abstract argument of citEntry().

ThierryO avatar Jan 25 '22 13:01 ThierryO

Thanks @ThierryO

I'm having the same error message with a different use case.

But still whilst calling pkgdown::build_site()?

maelle avatar Jan 26 '22 13:01 maelle

Alright, I went with the suggestion of @dmurdoch to escape any < characters in the macro when running with pkgdown, which seems to fix the errors :-)

rickhelmus avatar Feb 09 '22 16:02 rickhelmus

I've tried again with the latest development version (session info below). The problem occurs with this commit

 pkgdown::build_site()
-- Installing package into temporary library -------------------------------------------
== Building pkgdown site =======================================================
-- Initialising site -----------------------------------------------------------
-- Building home ---------------------------------------------------------------
Error in read_xml.raw(charToRaw(enc2utf8(x)), "UTF-8", ..., as_html = as_html,  : 
  Name doi:10.5281 is not XML Namespace compliant [202]
Error: callr subprocess failed: Name doi:10.5281 is not XML Namespace compliant [202]
─ Session info ───────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.1.2 (2021-11-01)
 os       Ubuntu 20.04.3 LTS
 system   x86_64, linux-gnu
 ui       RStudio
 language nl_BE:nl
 collate  nl_BE.UTF-8
 ctype    nl_BE.UTF-8
 tz       Europe/Brussels
 date     2022-02-24
 rstudio  2022.06.0-daily+140 Spotted Wakerobin (desktop)
 pandoc   2.14.0.3 @ /usr/bin/pandoc

─ Packages ───────────────────────────────────────────────────────────────────────────
 package     * version    date (UTC) lib source
 askpass       1.1        2019-01-13 [1] CRAN (R 4.1.0)
 base64enc     0.1-3      2015-07-28 [1] CRAN (R 4.1.0)
 brio          1.1.3      2021-11-30 [1] CRAN (R 4.1.2)
 bslib         0.3.1      2021-10-06 [1] CRAN (R 4.1.1)
 cachem        1.0.6      2021-08-19 [1] CRAN (R 4.1.1)
 callr         3.7.0      2021-04-20 [1] CRAN (R 4.1.0)
 cli           3.2.0      2022-02-14 [1] CRAN (R 4.1.2)
 cpp11         0.4.2      2021-11-30 [1] CRAN (R 4.1.2)
 crayon        1.5.0      2022-02-14 [1] CRAN (R 4.1.2)
 curl          4.3.2      2021-06-23 [1] CRAN (R 4.1.0)
 desc          1.4.0.9000 2022-01-05 [1] https://ropensci.r-universe.dev (R 4.1.2)
 digest        0.6.29     2021-12-01 [1] CRAN (R 4.1.2)
 downlit       0.4.0      2021-10-29 [1] CRAN (R 4.1.2)
 ellipsis      0.3.2      2021-04-29 [1] CRAN (R 4.1.0)
 evaluate      0.15       2022-02-18 [1] CRAN (R 4.1.2)
 fansi         1.0.2      2022-01-14 [1] CRAN (R 4.1.2)
 fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.1.0)
 fs            1.5.2      2021-12-08 [1] CRAN (R 4.1.2)
 glue          1.6.2      2022-02-24 [1] CRAN (R 4.1.2)
 highr         0.9        2021-04-16 [1] CRAN (R 4.1.0)
 htmltools     0.5.2      2021-08-25 [1] CRAN (R 4.1.1)
 httr          1.4.2      2020-07-20 [1] CRAN (R 4.1.0)
 jquerylib     0.1.4      2021-04-26 [1] CRAN (R 4.1.0)
 jsonlite      1.8.0      2022-02-22 [1] CRAN (R 4.1.2)
 knitr         1.37       2021-12-16 [1] CRAN (R 4.1.2)
 lifecycle     1.0.1      2021-09-24 [1] CRAN (R 4.1.1)
 magrittr      2.0.2      2022-01-26 [1] CRAN (R 4.1.2)
 memoise       2.0.1      2021-11-26 [1] CRAN (R 4.1.2)
 mime          0.12       2021-09-28 [1] CRAN (R 4.1.1)
 openssl       1.4.6      2021-12-19 [1] CRAN (R 4.1.2)
 pillar        1.7.0      2022-02-01 [1] CRAN (R 4.1.2)
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.1.0)
 pkgdown       2.0.2.9000 2022-02-24 [1] Github (r-lib/pkgdown@ae7363f)
 processx      3.5.2      2021-04-30 [1] CRAN (R 4.1.0)
 ps            1.6.0      2021-02-28 [1] CRAN (R 4.1.0)
 purrr         0.3.4      2020-04-17 [1] CRAN (R 4.1.0)
 R6            2.5.1      2021-08-19 [1] CRAN (R 4.1.1)
 ragg          1.2.2      2022-02-21 [1] CRAN (R 4.1.2)
 rappdirs      0.3.3      2021-01-31 [1] CRAN (R 4.1.0)
 rlang         1.0.1      2022-02-03 [1] CRAN (R 4.1.2)
 rmarkdown     2.11       2021-09-14 [1] CRAN (R 4.1.1)
 rprojroot     2.0.2      2020-11-15 [1] CRAN (R 4.1.0)
 sass          0.4.0      2021-05-12 [1] CRAN (R 4.1.0)
 stringi       1.7.6      2021-11-29 [1] CRAN (R 4.1.2)
 stringr       1.4.0      2019-02-10 [1] CRAN (R 4.1.0)
 sys           3.4        2020-07-23 [1] CRAN (R 4.1.0)
 systemfonts   1.0.4      2022-02-11 [1] CRAN (R 4.1.2)
 textshaping   0.3.6      2021-10-13 [1] CRAN (R 4.1.1)
 tibble        3.1.6      2021-11-07 [1] CRAN (R 4.1.2)
 tinytex       0.37       2022-02-16 [1] CRAN (R 4.1.2)
 utf8          1.2.2      2021-07-24 [1] CRAN (R 4.1.1)
 vctrs         0.3.8      2021-04-29 [1] CRAN (R 4.1.0)
 whisker       0.4        2019-08-28 [1] CRAN (R 4.1.0)
 withr         2.4.3      2021-11-30 [1] CRAN (R 4.1.2)
 xfun          0.29       2021-12-14 [1] CRAN (R 4.1.2)
 xml2          1.3.3      2021-11-30 [1] CRAN (R 4.1.2)
 yaml          2.3.5      2022-02-21 [1] CRAN (R 4.1.2)

ThierryO avatar Feb 24 '22 10:02 ThierryO