[Rd] R 2.5.0 devel try issue in conjuntion with S4 method dispatch
Seth Falcon
sfalcon at fhcrc.org
Thu Mar 15 23:05:32 CET 2007
ml-it-r-devel at epigenomics.com writes:
> Investigating this new implementation I come across an issue in
> conjuntion with using S4 classes and methods. try(expr) does not return an
> object with attribute 'try-error' in case of method dispatch failure
> in the wrapped expression which to me seems not
> quite correct.
We've seen some similar issues but had not had time to track them
down.
> Examples to reproduce the observation:
It isn't S4 specific. The issue seems more about anonymous
calls/functions.
ll = list()
ll[[1]] = function(x) stop("died")
v = try(do.call(ll[[1]], list(1)), silent=TRUE)
Error in as.list(call)[[1]] == "doTryCatch" :
comparison (1) is possible only for atomic and list types
> v
Error: object "v" not found
I don't fully understand why the call is being computed, but the
following seems to get things going.
+ seth
--- a/src/library/base/R/New-Internal.R
+++ b/src/library/base/R/New-Internal.R
@@ -7,7 +7,8 @@ try <- function(expr, silent = FALSE) {
## Patch up the call to produce nicer result for testing as
## try(stop(...)). This will need adjusting if the
## implementation of tryCatch changes.
- if (as.list(call)[[1]] == "doTryCatch")
+ callFun <- as.list(call)[[1]]
+ if (is.name(callFun) && callFun == "doTryCatch")
call <- sys.call(-4)
dcall <- deparse(call)[1]
prefix <- paste("Error in", dcall, ": ")
--
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org
More information about the R-devel
mailing list