[R-pkg-devel] try() in R CMD check --as-cran
Henrik Bengtsson
henr|k@bengt@@on @end|ng |rom gm@||@com
Fri Jun 7 19:49:49 CEST 2019
Duncan and others, see one of Serguei comments above. Specifically,
`R CMD check --as-cran` will set
_R_CHECK_LENGTH_1_LOGIC2_="package:_R_CHECK_PACKAGE_NAME_,abort,verbose"
which will (i) check those coding mistakes only in the package that is
checked but not any of its dependencies, (ii) it will abort R on such
errors, and (iii) print verbose output. I think this type of R CMD
check behavior only exists for '_R_CHECK_LENGTH_1_LOGIC2_' checks.
This is in contrast to:
_R_CHECK_LENGTH_1_LOGIC2_=TRUE
which will produce an ordinary error condition that can be captured.
Example:
Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "TRUE")
res <- tryCatch(c(TRUE, TRUE) && FALSE, error = identity)
str(res)
## List of 2
## $ message: chr "'length(x) = 2 > 1' in coercion to 'logical(1)'"
## $ call : language c(TRUE, TRUE) && FALSE
## - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "abort,verbose")
res <- tryCatch(c(TRUE, TRUE) && FALSE, error = identity)
----------- FAILURE REPORT --------------
--- failure: length > 1 in coercion to logical ---
--- srcref ---
:
--- package (from environment) ---
package:stats
--- call from context ---
doTryCatch(return(expr), name, parentenv, handler)
--- call from argument ---
c(TRUE, TRUE) && FALSE
--- R stacktrace ---
where 1: doTryCatch(return(expr), name, parentenv, handler)
where 2: tryCatchOne(expr, names, parentenv, handlers[[1L]])
where 3: tryCatchList(expr, classes, parentenv, handlers)
where 4: tryCatch(c(TRUE, TRUE) && FALSE, error = identity)
--- value of length: 2 type: logical ---
[1] TRUE TRUE
--- function from context ---
function (expr, name, parentenv, handler)
{
.Internal(.addCondHands(name, list(handler), parentenv, environment(),
FALSE))
expr
}
<bytecode: 0x559818c0ce70>
<environment: 0x55981a72abc0>
--- function search by body ---
----------- END OF FAILURE REPORT --------------
Fatal error: length > 1 in coercion to logical
[here R terminates]
/Henrik
On Fri, Jun 7, 2019 at 10:26 AM Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>
> On 07/06/2019 12:32 p.m., William Dunlap wrote:
> > The length-condition-not-equal-to-one checks will cause R to shutdown
> > even if the code in a tryCatch().
>
> That's strange. I'm unable to reproduce it with my tries, and John's
> package is no longer online. Do you have an example I could look at?
>
> Duncan Murdoch
>
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com <http://tibco.com>
> >
> >
> > On Fri, Jun 7, 2019 at 7:47 AM Duncan Murdoch <murdoch.duncan using gmail.com
> > <mailto:murdoch.duncan using gmail.com>> wrote:
> >
> > On 07/06/2019 9:46 a.m., J C Nash wrote:
> > > Should try() not stop those checks from forcing an error?
> >
> > try(stop("msg")) will print the error message, but won't stop
> > execution. Presumably the printed message is what is causing you
> > problems. If you want to suppress that, use
> >
> > try(stop("msg"), silent = TRUE)
> >
> > Duncan Murdoch
> >
> > >
> > > I recognize that this is the failure -- it is indeed the check
> > I'm trying to
> > > catch -- but I don't want tests of such checks to fail my package.
> > >
> > > JN
> > >
> > > On 2019-06-07 9:31 a.m., Sebastian Meyer wrote:
> > >> The failure stated in the R CMD check failure report is:
> > >>
> > >>> --- failure: length > 1 in coercion to logical ---
> > >>
> > >> This comes from --as-cran performing useful extra checks via
> > setting the
> > >> environment variable _R_CHECK_LENGTH_1_LOGIC2_, which means:
> > >>
> > >>> check if either argument of the binary operators && and || has
> > length greater than one.
> > >>
> > >> (see
> > https://cran.r-project.org/doc/manuals/r-release/R-ints.html#Tools)
> > >>
> > >> The failure report also states the source of the failure:
> > >>
> > >>> --- call from context ---
> > >>> fchk(x, benbad, trace = 3, y)
> > >>> --- call from argument ---
> > >>> is.infinite(fval) || is.na <http://is.na>(fval)
> > >>
> > >> The problem is that both is.infinite(fval) and is.na
> > <http://is.na>(fval) return
> > >> vectors of length 10 in your test case:
> > >>
> > >>> --- value of length: 10 type: logical ---
> > >>> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> > >>
> > >> The || operator works on length 1 Booleans. Since fval can be of
> > length
> > >> greater than 1 at that point, the proper condition seems to be:
> > >>
> > >> any(is.infinite(fval)) || any(is.na <http://is.na>(fval))
> > >>
> > >> Best regards,
> > >>
> > >> Sebastian
> > >>
> > >>
> > >> Am 07.06.19 um 14:53 schrieb J C Nash:
> > >>> Sorry reply not quicker. For some reason I'm not getting
> > anything in the thread I started!
> > >>> I found the responses in the archives. Perhaps cc:
> > nashjc using uottawa.ca <mailto:nashjc using uottawa.ca> please.
> > >>>
> > >>> I have prepared a tiny (2.8K) package at
> > >>> http://web.ncf.ca/nashjc/jfiles/fchk_2019-6.5.tar.gz
> > >>>
> > >>> R CMD check --> OK
> > >>>
> > >>> R CMD check --as-cran --> 1 ERROR, 1 NOTE
> > >>>
> > >>> The error is in an example:
> > >>>
> > >>>> benbad<-function(x, y){
> > >>>> # y may be provided with different structures
> > >>>> f<-(x-y)^2
> > >>>> } # very simple, but ...
> > >>>>
> > >>>> y<-1:10
> > >>>> x<-c(1)
> > >>>> cat("test benbad() with y=1:10, x=c(1)\n")
> > >>>> tryfc01 <- try(fc01<-fchk(x, benbad, trace=3, y))
> > >>>> print(tryfc01)
> > >>>> print(fc01)
> > >>>
> > >>> There's quite a lot of output, but it doesn't make much sense
> > to me, as
> > >>> it refers to code that I didn't write.
> > >>>
> > >>> The function fchk is attempting to check if functions provided for
> > >>> optimization do not violate some conditions e.g., character
> > rather than
> > >>> numeric etc.
> > >>>
> > >>> JN
> > >>>
> > >>>
> > >>> On 2019-06-07 8:44 a.m., J C Nash wrote:
> > >>>> Uwe Ligges ||gge@ @end|ng |rom @t using t|@t|k using tu-dortmund@de
> > >>>> Fri Jun 7 11:44:37 CEST 2019
> > >>>>
> > >>>> Previous message (by thread): [R-pkg-devel] try() in R
> > CMD check --as-cran
> > >>>> Next message (by thread): [R-pkg-devel] using package
> > data in package code
> > >>>> Messages sorted by: [ date ] [ thread ] [ subject ] [
> > author ]
> > >>>>
> > >>>> Right, what problem are you talking about? Can you tell us
> > which check
> > >>>> it is and what it actually complained about.
> > >>>> There is no check that looks at the sizes of x and y in
> > exypressions
> > >>>> such as
> > >>>> (x - y)^2.
> > >>>> as far as I know.
> > >>>>
> > >>>> Best,
> > >>>> Uwe
> > >>>>
> > >>>> On 07.06.2019 10:33, Berry Boessenkool wrote:
> > >>>>>
> > >>>>> Not entirely sure if this is what you're looking for:
> > >>>>>
> > https://github.com/wch/r-source/blob/trunk/src/library/tools/R/check.R
> > >>>>> It does contain --as-cran a few times and there's the
> > change-history:
> > >>>>>
> > https://github.com/wch/r-source/commits/trunk/src/library/tools/R/check.R
> > >>>>>
> > >>>>> Regards,
> > >>>>> Berry
> > >>>>>
> > >>>>>
> > >>>>> ________________________________
> > >>>>> From: R-package-devel <r-package-devel-bounces using
> > r-project.org <http://r-project.org>> on behalf of J C Nash
> > <profjcnash using gmail.com <http://gmail.com>>
> > >>>>> Sent: Thursday, June 6, 2019 15:03
> > >>>>> To: List r-package-devel
> > >>>>> Subject: [R-pkg-devel] try() in R CMD check --as-cran
> > >>>>>
> > >>>>> After making a small fix to my optimx package, I ran my usual
> > R CMD check --as-cran.
> > >>>>>
> > >>>>> To my surprise, I got two ERRORs unrelated to the change. The
> > errors popped up in
> > >>>>> a routine designed to check the call to the user objective
> > function. In particular,
> > >>>>> one check is that the size of vectors is the same in
> > expressions like (x - y)^2.
> > >>>>> This works fine with R CMD check, but the --as-cran seems to
> > have changed and it
> > >>>>> pops an error, even when the call is inside try(). The irony
> > that the routine in
> > >>>>> question is intended to avoid problems like this is not lost
> > on me.
> > >>>>>
> > >>>>> I'm working on a small reproducible example, but it's not
> > small enough yet.
> > >>>>> In the meantime, I'm looking for the source codes of the
> > scripts for "R CMD check" and
> > >>>>> "R CMD check --as-cran" so I can work out why there is this
> > difference, which seems
> > >>>>> to be recent.
> > >>>>>
> > >>>>> Can someone send/post a link? I plan to figure this out and
> > provide feedback,
> > >>>>> as I suspect it is going to affect others. However, it may be
> > a few days or even
> > >>>>> weeks if past experience is a guide.
> > >>>>>
> > >>>>> JN
> > >>>>>
> > >>>>> ______________________________________________
> > >>>>> R-package-devel using r-project.org <http://r-project.org>
> > mailing list
> > >>>>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> > >>>>>
> > >>>>> [[alternative HTML version deleted]]
> > >>>>>
> > >>>>> ______________________________________________
> > >>>>> R-package-devel using r-project.org <http://r-project.org>
> > mailing list
> > >>>>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> > >>>>>
> > >>>>
> > >>>
> > >>> ______________________________________________
> > >>> R-package-devel using r-project.org
> > <mailto:R-package-devel using r-project.org> mailing list
> > >>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> > >>>
> > >>
> > >> ______________________________________________
> > >> R-package-devel using r-project.org
> > <mailto:R-package-devel using r-project.org> mailing list
> > >> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> > >>
> > >
> > > ______________________________________________
> > > R-package-devel using r-project.org
> > <mailto:R-package-devel using r-project.org> mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-package-devel
> > >
> >
> > ______________________________________________
> > R-package-devel using r-project.org <mailto:R-package-devel using r-project.org>
> > mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
More information about the R-package-devel
mailing list