mhunter1 / dynr

Dynamic Modeling in R
5 stars 6 forks source link

Use safe type check to fix CRAN failure #244

Closed mhunter1 closed 4 years ago

mhunter1 commented 4 years ago

As maintainer, I received the following email from CRAN:

Dear maintainer,

Please see the problems shown on https://cran.r-project.org/web/checks/check_results_dynr.html.

Specifically, see the problems shown for the r-devel Linux checks.

These can be reproduced by checking with --as-cran using current r-devel, which sets

_R_CHECK_LENGTH_1CONDITION="package:_R_CHECK_PACKAGENAME,verbose"

in the check environment to the effect that conditions of length greater than one in 'if' and 'while' statements executing in the package being checked give an error.

The NEWS for current r-devel contains

  • matrix objects now also inherit from class "array", namely, e.g., class(diag(1)) is c("matrix", "array") which invalidates code assuming that length(class(obj)) == 1, an incorrect assumption that is less frequently fulfilled now.

Apparently your package no longer works correctly when class(matrix(...)) gives a vector of length two and conditions of length greater than one in 'if' or 'while' give an error: please fix as necessary.

See https://developer.r-project.org/Blog/public/2019/11/09/when-you-think-class.-think-again/index.html> for more information about correctly using class() in package code.

Please correct before 2020-02-15 to safely retain your package on CRAN.

Note that this will be the final reminder.

Best, -k

By following the links, it seems like the below from R/dynrCook.R is the problem

if (class(V1) == "try-error") {
    failHess <- failHess + 1
    warning("Hessian is not invertible; used pseudo-inverse.\nModel might not be identified or is not at an optimal solution.\nRegard standard errors suspiciously.",
        call. = FALSE)
    V1 <- MASS::ginv(useHess)
}

We need to change the line class(V1) == "try-error" which assume that length(class(V1)) == 1.