[Rd] Compatibility issues caused by new simplify argument in apply function

Lukas Lehnert |uk@@|ehnert @end|ng |rom goog|em@||@com
Fri May 22 12:26:05 CEST 2020


Dear R Developers,

the new  simplify argument in apply causes that my package (hsdar) does not 
pass the 
checks in R-devel.

The workaround, Kurt Hornik send me, is working for the R-code:
if("simplify" %in% names(formals(base::apply))) 
 do something 
else 
 do something else

Unfortunately, I cannot conditionalize the man pages of the functions. I get 
the message 
that "applySpeclib.Rd:12-14: Section \Sexpr is unrecognized and will be 
dropped" if I try to 
dynamically define the entire usage section. If I try to use \Sexpr inside the 
\usage section, 
I get the following warning: "applySpeclib.Rd:13-15: Tag \Sexpr is invalid in 
a \usage block"

Does anybody have an idea how to proceed. The full code is available below.

Thanks

Lukas


*1. Code for full usage section:*
..
\description{
Apply function over all spectra or a subset of spectra in a \code{Speclib}.
}

\Sexpr[echo=TRUE,results=rd,stage=install]{
  hsdar:::.applyInHelp1("Speclib", usage = TRUE)
}

\arguments{
..

*Function .applyInHelp1*
.applyInHelp1 <- function(fun_name, usage)
{
  if (usage)
  {
    if ("simplify" %in% names(formals(base::apply))) 
    {
      return(paste0("\\usage{\n",
                    "\\S4method{apply}{", fun_name, "}(X, MARGIN, FUN, ..., 
simplify = TRUE)\n",
                    "}"))
    } else {
      return(paste0("\\usage{\n",
                    "\\S4method{apply}{", fun_name, "}(X, MARGIN, FUN, ...)
\n",
                    "}"))
    }
  } else {
    if ("simplify" %in% names(formals(base::apply))) 
    {
      return("}\n\\item{simplify}{Currently ignored")
    } else {
      return("")
    }
  }
}


*2. Using \Sexpr inside the \usage block*
\usage{
\S4method{apply}{Speclib}(X, FUN, bySI = NULL, ...
\Sexpr[echo=TRUE,results=rd,stage=install]{
  hsdar:::.applyInHelp2(usage = TRUE)
}
)
}


*Function .applyInHelp2*
.applyInHelp2 <- function(usage)
{
  if (usage)
  {
    if ("simplify" %in% names(formals(base::apply))) 
    {
      return(", simplify = TRUE)")
    } 
  } else {
    if ("simplify" %in% names(formals(base::apply))) 
    {
      return("}\n\\item{simplify}{Currently ignored")
    } else {
      return("")
    }
  }
}



More information about the R-devel mailing list