[R-pkg-devel] R CMD checks URLs formatted for LaTeX instead of using the non-LaTeX URLs, and fails

Ralf Herold r@||@hero|d @end|ng |rom gmx@net
Sat Jul 2 12:01:38 CEST 2022


Hello, in my package documentation I want to include URLs with query string parameters and anchors, within a table. A minimally reproducible example is this content in file "man/mre.Rd":

\name{mre}
\title{mre}
\description{mre}
\details{
\tabular{l}{
  \ifelse{latex}{\href{https://clinicaltrials.gov/ct2/results?cond=Infections\&rslt=With\#tableTop}{latex link}}{\href{https://clinicaltrials.gov/ct2/results?cond=Infections&rslt=With#tableTop}{non-latex link}}
}}

The ifelse{}{}{} construct is necessary since ampersands in a table need to be escaped for LaTeX rendering.

Each of the following commands checks and renders the respective output correctly:

tools::checkRd("man/mre.Rd")
tools::Rd2txt("man/mre.Rd")
tools::Rd2latex("man/mre.Rd")
tools::Rd2HTML("man/mre.Rd")
system2("R", c("CMD", "Rd2pdf", "man/mre.Rd"))

However, rhub::check_for_cran() results in NOTES:

Found the following (possibly) invalid URLs:
  URL: https://clinicaltrials.gov/ct2/results?cond=Infections\&rslt=With\#tableTop
    From: man/mre.Rd
    Status: 400
    Message: Bad Request

Subsequently, CRAN maintainers refused accepting the package.

However, the underlying cause is that, during such checks, all apparent URLs are extracted from .Rd files, irrespective of any \ifelse{}{}{} constructs. This in turn is due to such checks involving calls to function ".get_urls_from_Rd" without setting its argument "ifdef" to TRUE.

Here is how to see this behaviour:

db <- tools::Rd_db(dir = ".")

# get functions
source("https://svn.r-project.org/R/trunk/src/library/tools/R/urltools.R")
source("https://svn.r-project.org/R/trunk/src/library/tools/R/utils.R")
.Rd_deparse <- tools:::.Rd_deparse
RdTags <- tools:::RdTags

# default, leading to invalid url in [1]
# > .get_urls_from_Rd(db)
# [1] "https://clinicaltrials.gov/ct2/results?cond=Infections\\&rslt=With\\#tableTop"
# [2] "https://clinicaltrials.gov/ct2/results?cond=Infections&rslt=With#tableTop"

# returning relevant valid url
#> .get_urls_from_Rd(db, ifdef = TRUE)
# [1] "https://clinicaltrials.gov/ct2/results?cond=Infections&rslt=With#tableTop"

This can be addressed by either:

-- changing the signature of ".get_urls_from_Rd" in line 50 in https://svn.r-project.org/R/trunk/src/library/tools/R/urltools.R to read "ifdef = TRUE". Of note, this function has a code block to handle such ifdef constructs which indicates it should be possible to use them in Rd files.

-- changing the calling function "url_db_from_package_Rd_db" to include "ifdef = TRUE" on line 178 in https://svn.r-project.org/R/trunk/src/library/tools/R/urltools.R

Please advise how to advance on this issue, thank you very much.

Greetings
Ralf



More information about the R-package-devel mailing list