You didn't explained what the error is. This is what it looks like to me, but I'm probably wrong in some details:

1. R-devel added an argument to the apply() function, so the header has changed from

  function (X, MARGIN, FUN, ...)

to

  function(X, MARGIN, FUN, ..., simplify = TRUE)

2. Your package converted the function apply() to an S4 generic.

3. Now the signatures of your methods for this generic need to have the simplify argument, but if you do that, they won't work in previous versions of R.

You'd like to have conditional code and documentation to depend on the version of R.

Is that all correct?

I don't think it's possible, for the reasons you found. Certainly you can have conditional code, but the docs are going to fail.

One thing that might work is in versions of R before this change, export your own version of apply, with the change in place, i.e.

if(!("simplify" %in% names(formals(base::apply))))
  apply <- function(X, MARGIN, FUN, ..., simplify = TRUE) {
    base::apply(X, MARGIN, FUN, ...)
  }

and then conditionally export "apply" in these old versions. Then your docs could match the new version everywhere.

Another thing is to maintain two versions of your package, one for R versions before the change, another for versions after the change. Add appropriate entries in the DESCRIPTION file, e.g.

Depends:  R (> 4.0)

Another is to argue with R Core that this change to a really old function is too hard to accommodate, and they should back it out, maybe by making a new function with the new signature.

Or you could make a new function with the old signature, and use that instead of apply().

Duncan Murdoch



On 22/05/2020 6:26 a.m., Lukas Lehnert via R-devel wrote:
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("")
     }
   }
}

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to