Re: [R-pkg-devel] [External] Re: try() in R CMD check --as-cran

2019-06-14 Thread Tomas Kalibera
The advantage of "abort" (R_Suicide) over the default (R error) is that 
it cannot be caught accidentally, so that one can detect more errors, 
and it may be easier to find where the error happened. To make the 
default behavior less surprising/more user friendly, and to allow 
intentional catching of these errors, the default for R CMD check 
--as-cran was changed in R-devel so that the normal R error is thrown, 
and the documentation in R Internals updated accordingly. One thus has 
to set the variable explicitly to get the stricter checks.


Best
Tomas

On 6/7/19 8:51 PM, Tierney, Luke wrote:

A simplified version without a package:

Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_"="abort,verbose")
tryCatch(1:3 || 1, error = identity)

Running this aborts the session since it calls R_Suicide without first
signaling a condition to try any available handlers. Should be easy to
change, but I don't know if there are any downsides for the CRAN
workflow. I'll look into it.

Best,

luke


On Fri, 7 Jun 2019, William Dunlap wrote:


I've attached a package, ppp_0.1.tar.gz, which probably will not get
through to R-help, that illustrates this.
It contains one function which, by default, triggers a condition-length>1
issue:
   f <- function(x = 1:3)
   {
   if (x > 1) {
   x <- -x
   }
   stop("this function always gives an error")
   }
and the help file example is
   try(f())

Then
   env _R_CHECK_LENGTH_1_CONDITION_=abort,verbose R-3.6.0 CMD check
--as-cran ppp_0.1.tar.gz
results in
* checking examples ... ERROR
Running examples in ‘ppp-Ex.R’ failed
The error most likely occurred in:


base::assign(".ptime", proc.time(), pos = "CheckExEnv")
### Name: f
### Title: Cause an error
### Aliases: f
### Keywords: error

### ** Examples

try(f())

--- FAILURE REPORT --
--- failure: the condition has length > 1 ---
--- srcref ---
:
--- package (from environment) ---
ppp
--- call from context ---
f()
--- call from argument ---
if (x > 1) {
x <- -x
}
--- R stacktrace ---
where 1: f()
where 2: doTryCatch(return(expr), name, parentenv, handler)
where 3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
where 4: tryCatchList(expr, classes, parentenv, handlers)
where 5: tryCatch(expr, error = function(e) {
call <- conditionCall(e)
if (!is.null(call)) {
if (identical(call[[1L]], quote(doTryCatch)))
call <- sys.call(-4L)
dcall <- deparse(call)[1L]
prefix <- paste("Error in", dcall, ": ")
LONG <- 75L
sm <- strsplit(conditionMessage(e), "\n")[[1L]]
w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")
if (is.na(w))
w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],
type = "b")
if (w > LONG)
prefix <- paste0(prefix, "\n  ")
}
else prefix <- "Error : "
msg <- paste0(prefix, conditionMessage(e), "\n")
.Internal(seterrmessage(msg[1L]))
if (!silent && isTRUE(getOption("show.error.messages"))) {
cat(msg, file = outFile)
.Internal(printDeferredWarnings())
}
invisible(structure(msg, class = "try-error", condition = e))
})
where 6: try(f())

--- value of length: 3 type: logical ---
[1] FALSE  TRUE  TRUE
--- function from context ---
function (x = 1:3)
{
if (x > 1) {
x <- -x
}
stop("this function always gives an error")
}


--- function search by body ---
Function f in namespace ppp has this body.
--- END OF FAILURE REPORT --
Fatal error: the condition has length > 1
* checking PDF version of manual ... OK
* DONE

Status: 1 ERROR, 1 NOTE
See
  ‘/tmp/bill/ppp.Rcheck/00check.log’
for details.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 7, 2019 at 10:21 AM Duncan Murdoch 
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 


On Fri, Jun 7, 2019 at 7:47 AM Duncan Murdoch mailto:murdoch.dun...@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 ---
 >>
  

Re: [R-pkg-devel] [External] Re: try() in R CMD check --as-cran

2019-06-07 Thread Tierney, Luke
A simplified version without a package:

Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_"="abort,verbose")
tryCatch(1:3 || 1, error = identity)

Running this aborts the session since it calls R_Suicide without first
signaling a condition to try any available handlers. Should be easy to
change, but I don't know if there are any downsides for the CRAN
workflow. I'll look into it.

Best,

luke


On Fri, 7 Jun 2019, William Dunlap wrote:

> I've attached a package, ppp_0.1.tar.gz, which probably will not get
> through to R-help, that illustrates this.
> It contains one function which, by default, triggers a condition-length>1
> issue:
>   f <- function(x = 1:3)
>   {
>   if (x > 1) {
>   x <- -x
>   }
>   stop("this function always gives an error")
>   }
> and the help file example is
>   try(f())
>
> Then
>   env _R_CHECK_LENGTH_1_CONDITION_=abort,verbose R-3.6.0 CMD check
> --as-cran ppp_0.1.tar.gz
> results in
> * checking examples ... ERROR
> Running examples in ‘ppp-Ex.R’ failed
> The error most likely occurred in:
>
>> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
>> ### Name: f
>> ### Title: Cause an error
>> ### Aliases: f
>> ### Keywords: error
>>
>> ### ** Examples
>>
>> try(f())
> --- FAILURE REPORT --
> --- failure: the condition has length > 1 ---
> --- srcref ---
> :
> --- package (from environment) ---
> ppp
> --- call from context ---
> f()
> --- call from argument ---
> if (x > 1) {
>x <- -x
> }
> --- R stacktrace ---
> where 1: f()
> where 2: doTryCatch(return(expr), name, parentenv, handler)
> where 3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
> where 4: tryCatchList(expr, classes, parentenv, handlers)
> where 5: tryCatch(expr, error = function(e) {
>call <- conditionCall(e)
>if (!is.null(call)) {
>if (identical(call[[1L]], quote(doTryCatch)))
>call <- sys.call(-4L)
>dcall <- deparse(call)[1L]
>prefix <- paste("Error in", dcall, ": ")
>LONG <- 75L
>sm <- strsplit(conditionMessage(e), "\n")[[1L]]
>w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")
>if (is.na(w))
>w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],
>type = "b")
>if (w > LONG)
>prefix <- paste0(prefix, "\n  ")
>}
>else prefix <- "Error : "
>msg <- paste0(prefix, conditionMessage(e), "\n")
>.Internal(seterrmessage(msg[1L]))
>if (!silent && isTRUE(getOption("show.error.messages"))) {
>cat(msg, file = outFile)
>.Internal(printDeferredWarnings())
>}
>invisible(structure(msg, class = "try-error", condition = e))
> })
> where 6: try(f())
>
> --- value of length: 3 type: logical ---
> [1] FALSE  TRUE  TRUE
> --- function from context ---
> function (x = 1:3)
> {
>if (x > 1) {
>x <- -x
>}
>stop("this function always gives an error")
> }
> 
> 
> --- function search by body ---
> Function f in namespace ppp has this body.
> --- END OF FAILURE REPORT --
> Fatal error: the condition has length > 1
> * checking PDF version of manual ... OK
> * DONE
>
> Status: 1 ERROR, 1 NOTE
> See
>  ‘/tmp/bill/ppp.Rcheck/00check.log’
> for details.
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Fri, Jun 7, 2019 at 10:21 AM Duncan Murdoch 
> 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 
>>>
>>>
>>> On Fri, Jun 7, 2019 at 7:47 AM Duncan Murdoch >> > 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