Hola! look at the following:> test <- function() {+ options(warn=-1) + on.exit( options(warn=0)) + log(-1) + }> test()[1] NaN but what should be better, doesnt work:> test1 <- function() {+ oldwarn <- options("warn") + options(warn=-1) + on.exit( options(warn=oldwarn)) + log(-1) + }> test1()Error in options(...) : warn parameter invalid>What is wrong? (I have tried other versions, without success) Kjetil Halvorsen. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 27 Sep 2001 13:05:01 -0400, you wrote in message <3BB35C3C.C4FE9451 at umsanet.edu.bo>:>but what should be better, doesnt work: > >> test1 <- function() { >+ oldwarn <- options("warn") >+ options(warn=-1) >+ on.exit( options(warn=oldwarn)) >+ log(-1) >+ } >> test1() >Error in options(...) : warn parameter invalid >> > > >What is wrong? (I have tried other versions, without success)The problem is that you're assuming options() behaves the way par() does, i.e. that options("warn") returns a number. It doesn't, it returns a list. The simplest way to get what you want is probably test1 <- function() { oldwarn <- options(warn=-1) # first call on.exit( options(oldwarn)) # second call log(-1) } Notice that the first call that changes the option returns the old value, so you don't need two calls at the start; the second call that restores it just uses the list (which has the name of the option embedded in it). Duncan Murdoch -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
kjetil halvorsen <kjetilh at umsanet.edu.bo> writes:> but what should be better, doesnt work: > > > test1 <- function() { > + oldwarn <- options("warn") > + options(warn=-1) > + on.exit( options(warn=oldwarn)) > + log(-1) > + } > > test1() > Error in options(...) : warn parameter invalid > > > > > What is wrong? (I have tried other versions, without success)oldwarn is a list. Try> fix(test1) > test1()[1] NaN> test1function() { oldwarn <- options("warn") options(warn=-1) on.exit( options(warn=oldwarn$warn)) log(-1) } or maybe oldwarn <- unlist(options("warn")) ... on.exit(options(warn=oldwarn)) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._