[R] gracefully handing a library load error

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Mar 12 08:38:28 CET 2008


This is not a graceful error, and it needs to be corrected by the package 
(not 'library') maintainer.  R's own devices which need X11 do fail 
gracefully if the session is headless.

Meanwhile, there are other graphics devices which create SVGs and do not 
do this.  E.g. R-devel (to be 2.7.0) has an svg() device that does not 
require an X11 server, and there is a devSVG() in two packages, RSvgDevice 
and RSVGTipsDevice.

There are lots of ways to catch non-fatal errors (see ?options, ?stop, 
?try) but it was a deliberate decision not to allow continuation after a 
segfault (just wrap-up in interactive use).

On Wed, 12 Mar 2008, Will Holcomb wrote:

> I have an R program I am attempting to use to generate some SVGs. I've been
> using the cairoDevice library. When running a session not connected to an X
> session (like if I'm sshed in), attempting "library(cairoDevice)" causes:
>
> *** caught segfault ***
> address 0x8, cause 'memory not mapped'
>
> Traceback:
> 1: .C("R_gtk_setEventHandler", PACKAGE = "cairoDevice")
> 2: firstlib(which.lib.loc, package)
> 3: doTryCatch(return(expr), name, parentenv, handler)
> 4: tryCatchOne(expr, names, parentenv, handlers[[1]])
> 5: tryCatchList(expr, classes, parentenv, handlers)
> 6: tryCatch(expr, error = function(e) {    call <- conditionCall(e)    if
> (!is.null(call)) {        if (identical(call[[1]],
> quote(doTryCatch)))             call <- sys.call(-4)        dcall <-
> deparse(call)[1]        prefix <- paste("Error in", dcall, ": ")
> LONGCALL <- 30        if (nchar(dcall) > LONGCALL)             prefix <-
> paste(prefix, "\n\t", sep = "")    }    else prefix <- "Error : "    msg <-
> paste(prefix, conditionMessage(e), "\n", sep = "")
> .Internal(seterrmessage(msg[1]))    if (!silent && identical(getOption("
> show.error.messages"),         TRUE)) {        cat(msg, file =
> stderr())        .Internal(printDeferredWarnings())    }
> invisible(structure(msg, class = "try-error"))})
> 7: try(firstlib(which.lib.loc, package))
> 8: library(cairoDevice)
> aborting ...
> Segmentation fault (core dumped)
>
> I'm fine with the idea that Cairo somehow needs the X server to do its
> business. I would like to not have the program segfault however and instead
> just skip the SVG if it can't load the library. I've been hunting to see how
> to do error handling in R and I'm not really finding a good resource. Can
> anyone suggest one?
>
> Will
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list