[R] Edit function

François Pinard pinard at iro.umontreal.ca
Wed Jun 7 20:44:06 CEST 2006


[Pikounis, Bill [CNTUS]]

> view <- function(x) {
>   warnopt <- options()$warn
>   options(warn=-1)
>   on.exit({sink(); options(warn=warnopt)})
>   edit(x)
>   invisible()
> }

I'm surprised by the necessity of "sink()".  Presuming it is necessary 
indeed, the above could be simplified a bit like this (untested) code:

  view <- function(x) {
    on.exit(sink())
    invisible(suppressWarnings(edit(x)))
  }

The documentation for "suppressWarnings" is not overly clear about if 
the "warn" option is restored or not in case of error.  It says:

     'suppressWarnings' evaluates its expression in a context that
     ignores all warnings.

My exegesis :-) for that sentence would be that the context does not 
survive the error, and so, the "warn" option is not changed.

-- 
François Pinard   http://pinard.progiciels-bpi.ca



More information about the R-help mailing list