[Rd] as-cran issue
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]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as-cran issue
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 | e...@debian.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Error in R CMD check --as-cran ?
I've been fighting a CMD check error for coxme this morning. I thought I had it fixed, but instead I had forgotton --as-cran on my last test run. So the version just submitted to CRAN has warning messages in the log. I think it is an issue with CRAN. I've sent a message to R-devel asking for help. Since then, as a guess, I renamed my internal "ismat" function to something else and the error went away. Here is the code block in coxme, it is part of the "check user arguments for validity" block at the start of the function. Run coxme in a terminal and all is well, run R CMD check without as-cran and all is well, but with --as-cran the ismat function gives warnings. Changing the name to something else fixes the issue. The function exists only to save some typing. (No need to really read the block, just notice the multiple calls to ismat() ismat <- function (x) { inherits(x, c("matrix", "bdsmatrix", "Matrix"), which=FALSE) } if (missing(varlist) || is.null(varlist)) { varlist <- vector('list', nrandom) for (i in 1:nrandom) varlist[[i]] <- coxmeFull() #default } else { if (is.function(varlist)) varlist <- varlist() if (inherits(varlist, 'coxmevar')) varlist <- list(varlist) else if (ismat(varlist)) varlist <- list(coxmeMlist(list(varlist))) else { if (!is.list(varlist)) stop("Invalid varlist argument") if (all(sapply(varlist, ismat))) { # A list of matrices if (nrandom >1) stop(paste("An unlabeled list of matrices is", "ambiguous when there are multiple random terms")) else varlist <- list(coxmeMlist(varlist)) } else { #the user gave me a list, not all matrices for (i in 1:length(varlist)) { if (is.function(varlist[[i]])) varlist[[i]] <-varlist[[i]]() if (ismat(varlist[[i]])) varlist[[i]] <- coxmeMlist(list(varlist[[i]])) if (class(varlist[[i]]) != 'coxmevar') { if (is.list(varlist[[i]])) { if (all(sapply(varlist[[i]], ismat))) varlist[[i]] <- coxmeMlist(varlist[[i]]) else stop("Invalid varlist element") } else stop("Invalid varlist element") } } } } while(length(varlist) < nrandom) varlist <- c(varlist, list(coxmeFull())) } [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as-cran issue
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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as-cran issue
From R NEWS (changes in 3.6.0) Experimentally, setting environment variable _R_CHECK_LENGTH_1_LOGIC2_ will lead to warnings (or errors if the variable is set to a ‘true’ value) when && or || encounter and use arguments of length more than one. On 2020-01-13 11:46 a.m., Therneau, Terry M., Ph.D. via R-devel wrote: > 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 >> > > __ > 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
Re: [Rd] as-cran issue
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.0 You 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as-cran issue ==> set _R_CHECK_LENGTH_1_* settings!
> Ben Bolker > on Mon, 13 Jan 2020 11:49:09 -0500 writes: > From R NEWS (changes in 3.6.0) > Experimentally, setting environment variable _R_CHECK_LENGTH_1_LOGIC2_ > will lead to warnings (or errors if the variable is set to a ‘true’ > value) when && or || encounter and use arguments of length more than one. Indeed, thank you, Ben. Note (Dirk) this is not just something "by Henrik (..) as he tried to convince us all to use it more" I've activated this (and the other _R_CHECK_LENGTH_1_CONDITION_ ! ) for years (maybe not many years, it just feels like it), and *EVERY TIME* it triggers, it's been revealing a programmeR's thinko / bug / .., something where the code was clearly suboptimal and should've been improved. (Unfortunately, the bug has often been in packages, and sometimes I had to disable the setting when I wanted that "buggy" package to work ..) Occasionally being puristic, let me state this: __ /--\ | | | Every careful R programmer should use (something like "true",| | "verbose", or even package=... ) | | | | export _R_CHECK_LENGTH_1_CONDITION_=true | | export _R_CHECK_LENGTH_1_LOGIC2_=verbose | | | | in her/his ~/.profile equivalent (*) | \__/ *) well assuming a careful R programmer would never develop on Windows anyway (where you need different means to set such environment variables). > On 2020-01-13 11:46 a.m., Therneau, Terry M., Ph.D. via R-devel wrote: >> 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 >>> >> >> __ >> 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as-cran issue ==> set _R_CHECK_LENGTH_1_* settings!
Those of us stuck on Windows but who attempt to develop properly are wounded to the quick, sir! :) Avi On Mon, Jan 13, 2020 at 12:24 PM Martin Maechler wrote: > > Ben Bolker > > on Mon, 13 Jan 2020 11:49:09 -0500 writes: > > > From R NEWS (changes in 3.6.0) > > Experimentally, setting environment variable > _R_CHECK_LENGTH_1_LOGIC2_ > > will lead to warnings (or errors if the variable is set to a ‘true’ > > value) when && or || encounter and use arguments of length more than > one. > > Indeed, thank you, Ben. > > Note (Dirk) this is not just something > "by Henrik (..) as he tried to convince us all to use it more" > > I've activated this (and the other > _R_CHECK_LENGTH_1_CONDITION_ ! ) > for years (maybe not many years, it just feels like it), and *EVERY TIME* > it triggers, it's been revealing a programmeR's thinko / bug / .., > something where the code was clearly suboptimal and should've been > improved. > (Unfortunately, the bug has often been in packages, and sometimes I had to > disable the setting when I wanted that "buggy" package to work ..) > > Occasionally being puristic, let me state this: >__ > /--\ > | | > | Every careful R programmer should use (something like "true",| > | "verbose", or even package=... ) | > | | > | export _R_CHECK_LENGTH_1_CONDITION_=true | > | export _R_CHECK_LENGTH_1_LOGIC2_=verbose | > | | > | in her/his ~/.profile equivalent (*) | > \__/ > > > *) well assuming a careful R programmer would never develop on >Windows anyway (where you need different means to set such >environment variables). > > > > > On 2020-01-13 11:46 a.m., Therneau, Terry M., Ph.D. via R-devel > wrote: > >> 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 > >>> > >> > >> __ > >> 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 > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > -- Sent from Gmail Mobile [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as-cran issue, SOLVED
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]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as-cran issue, SOLVED
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 | e...@debian.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel