Where can I find out (and replicate) what options as-cran turns on?
The issue: the following lines generate an error in R CMD check --as-cran? for
coxme.? But
there is no error without as-cran nor is there one when I run the code in a
terminal window.
ismat <- function(x)? inherits(x, "matrix") || inherits(x,
"bdsmatrix") || inherits(x,
"Matrix")
if (ismat(kmat)? ) ....
(The second line is repeated multiple times for multiple arguments.? The ismat
function is
defined simply to save typing.)
The check log contains multiple instances of the lines below:
< Warning message:
< In if (ismat(kmat)) { :
<?? the condition has length > 1 and only the first element will be used
I don't see how the error could arise, but if I know what as-cran is doing
perhaps I can
replicate it.
>sessionInfo()
R Under development (unstable) (2020-01-13 r77659)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS
Matrix products: default
BLAS:?? /usr/local/src/R-devel/lib/libRblas.so
LAPACK: /usr/local/src/R-devel/lib/libRlapack.so
locale:
?[1] LC_CTYPE=en_US.UTF-8?????? LC_NUMERIC=C
?[3] LC_TIME=en_US.UTF-8??????? LC_COLLATE=C
?[5] LC_MONETARY=en_US.UTF-8??? LC_MESSAGES=en_US.UTF-8
?[7] LC_PAPER=en_US.UTF-8?????? LC_NAME=C
?[9] LC_ADDRESS=C?????????????? LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats???? graphics? grDevices utils???? datasets? methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.0 tools_4.0.0
>
[[alternative HTML version deleted]]
On 13 January 2020 at 10:02, Therneau, Terry M., Ph.D. via R-devel wrote:
| Where can I find out (and replicate) what options as-cran turns on?
See the file src/library/tools/R/check.R in the R sources, and grep for
as_cran which is the internal variable controlled by the --as-cran option
[...]
| The check log contains multiple instances of the lines below:
|
| < Warning message:
| < In if (ismat(kmat)) { :
| <?? the condition has length > 1 and only the first element will be used
|
| I don't see how the error could arise, but if I know what as-cran is doing
perhaps I can
| replicate it.
This was widely discussed on this list and should also be in the NEWS file.
The change is about what the message says: the if () tests a scalar logical,
it appears that ismat(kmat) returns more than a scalar.
There has always been an opt-in for this to error -- cf many messages by Henrik
over the years as he tried to convince us all to use it more.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Thanks for the feedback Dirk. I sent my follow-up before I saw it. Looking at the source code, it appears that there is no options() call to turn this on. Nor does "R --help" reveal a command line option. How then does a user turn this on outside of the R CMD check envirionment, so as to chase things like this down? The fact that 1. renaming my function makes the error go away, 2. my function is just a wrapper to inherits(), and 3. its a new error in code that hasn't changed, all point me towards some oddity with the check function. Terry On 1/13/20 10:22 AM, Dirk Eddelbuettel wrote:> > On 13 January 2020 at 10:02, Therneau, Terry M., Ph.D. via R-devel wrote: > | Where can I find out (and replicate) what options as-cran turns on? > > See the file src/library/tools/R/check.R in the R sources, and grep for > as_cran which is the internal variable controlled by the --as-cran option > > [...] > > | The check log contains multiple instances of the lines below: > | > | < Warning message: > | < In if (ismat(kmat)) { : > | <?? the condition has length > 1 and only the first element will be used > | > | I don't see how the error could arise, but if I know what as-cran is doing perhaps I can > | replicate it. > > This was widely discussed on this list and should also be in the NEWS file. > > The change is about what the message says: the if () tests a scalar logical, > it appears that ismat(kmat) returns more than a scalar. > > There has always been an opt-in for this to error -- cf many messages by Henrik > over the years as he tried to convince us all to use it more. > > > Dirk >
On 13/01/2020 11:02 a.m., Therneau, Terry M., Ph.D. via R-devel wrote:> Where can I find out (and replicate) what options as-cran turns on? > > The issue: the following lines generate an error in R CMD check --as-cran? for coxme.? But > there is no error without as-cran nor is there one when I run the code in a terminal window. > > ismat <- function(x)? inherits(x, "matrix") || inherits(x, "bdsmatrix") || inherits(x, > "Matrix") > if (ismat(kmat)? ) .... > > (The second line is repeated multiple times for multiple arguments.? The ismat function is > defined simply to save typing.) > > The check log contains multiple instances of the lines below: > > < Warning message: > < In if (ismat(kmat)) { : > <?? the condition has length > 1 and only the first element will be used > > I don't see how the error could arise, but if I know what as-cran is doing perhaps I can > replicate it. > > >sessionInfo() > R Under development (unstable) (2020-01-13 r77659) > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Ubuntu 18.04.3 LTS > > Matrix products: default > BLAS:?? /usr/local/src/R-devel/lib/libRblas.so > LAPACK: /usr/local/src/R-devel/lib/libRlapack.so > > locale: > ?[1] LC_CTYPE=en_US.UTF-8?????? LC_NUMERIC=C > ?[3] LC_TIME=en_US.UTF-8??????? LC_COLLATE=C > ?[5] LC_MONETARY=en_US.UTF-8??? LC_MESSAGES=en_US.UTF-8 > ?[7] LC_PAPER=en_US.UTF-8?????? LC_NAME=C > ?[9] LC_ADDRESS=C?????????????? LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats???? graphics? grDevices utils???? datasets? methods base > > loaded via a namespace (and not attached): > [1] compiler_4.0.0 tools_4.0.0You have ismat() defined in two places in the package. In the definition in coxme.R, you've got a typo: ismat <- function (x) { inherits(x, "matrix") || inherits(x, "bdsmatrix") | inherits(x, "Matrix") } Notice the "|" instead of "||". I can't see how this would lead to the issue you saw, but it should be fixed. It's not easy to say what --as-cran does, other than to look at the function that implements R CMD check. That function is the huge tools:::.check_packages. You can run it in an R session using options(warn = 2, error = recover) tools:::.check_packages(c("--as-cran", "coxme_2.2-14.tar.gz")) When I do that I get a different error report; it reports this test instead: if(class(varlist) == "coxmevar") That appears in a number of places in the coxme source, and clearly needs to be updated to use inherits(). Duncan Murdoch
Thank you to all who replied with helpful suggestions.?? I had to run off to meetings and talks for a bit so am now processing it all. 1. It turns out that the issue was not with coxme, but with bsdmatrix, a package that coxme calls.? It just happens to have a function ismat() with the same general purpose and some similar variable names, which led me down the rabbit hole.?? That package contained a "class(x) == " flaw, now fixed.?? (The fact that bdsmatrix has been stable and unchanged for nearly a decade helped with the deception.) 2. As pointed out by Duncan and Kurt, the coxme function also had a class(x)== flaw.? None of my test cases triggered this, but since 'x' is an argument that can be supplied by a user, it certainly would have happened in package use.? Good catch. 3. Dirk gave good input about the flags in R CMD check and how to find them.?? One more line in the "Writing R Extensions" manual would have been helpful, namely that many of the options are NOT available in the options() command nor as arguments to R.??? As near as I can tell, there is no way to turn on these logic checks within a standard R session.?? A desire to do this is where I started: I would have set options(warn=2, error=recover) and found the actual offender in a few minutes; and never had to bother all you worthy readers. 4. I agree completely with Martin that errors like this should not be ignored.? In fact, except for? "variable may be used before initialized" messages from the C compiler, I have become grateful for EVERY complaint that comes out R CMD check.?? Notice the verb "have become" -- I did not start out so enthusiastic. Again, thanks for the help. Terry T. [[alternative HTML version deleted]]
On 13 January 2020 at 14:51, Therneau, Terry M., Ph.D. wrote: | 3. Dirk gave good input about the flags in R CMD check and how to find them.?? One more | line in the "Writing R Extensions" manual would have been helpful, namely that many of the | options are NOT available in the options() command nor as arguments to R.??? As near as I | can tell, there is no way to turn on these logic checks within a standard R session.?? A Section 8 of R Internals: 8 Tools ******* The behavior of 'R CMD check' can be controlled through a variety of command line arguments and environment variables. [...] or online at https://cran.r-project.org/doc/manuals/r-release/R-ints.html#Tools Also, if I may, and as I may not have been clear enough earlier (as it confused at least Martin): these "rolling" tightenings of "standards" and tests are IMHO one the many rather clever "devices" R Core and CRAN use to keep improving the quality of the code we all produce. It's a good thing. That said, and just like Terry, I have also searched many times for these variables, and part of me thinks that it a crime that the material is spread over (at least) three different manuals but _c'est la vie_. Until we get a dedicated volunteer editor, or, deity forbid we decide to spend some (collective) money on professional documentation. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org