Within an user function, how are the warnings from an R function be trapped (such that some proper actions can be taken)? 'last.warning' is returned only at the top level. Pointers are appreciated. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Petra Steiner
2002-Apr-30 13:11 UTC
[R] read in a matrix, difference between 1.3.1 (Windows) and 1.4.1 (Unix)
Hello,
I am reading in a matrix with ignoring the first line. With the exception of
the first column (column names) each value is numeric.
Up to now the following worked well, although a bit slow.
tabx <- matrix(scan("myfile", what "", skip=1, quote =
""), byrow=T, nrow=reihenz, ncol=spaltenz)
print(tabx)
taby <- apply(tabx[1:reihenz,2:spaltenz], 2, as.numeric)
rownames(taby) <- tabx[,1]
print(taby)
Now, with Version 1.4.1 under Unix, for tabx I get a table with the first line
repeated many times. as.numeric is not applicable of course.
Maybe read.table would be better? But I have to read a lot of data!
Regards,
Petra Steiner
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thanks for the reply. The problem that I have in a nutshell is the
following:
usertest <- function {
...
reg<-polr(act~., data=mm)
summary(reg)
return(reg$AIC)
}
For some data, NaN's are produced (in sqrt(diag(vc))), and I'd like to
trap
this condition and any other warnings, so that a negative value, say, can be
returned to the calling function to indicate the warning condition.
Warnings from
summary() are produced and placed in 'last.warning' but that is
accessible
only at the top-level, not within usertest(); I've tried setting
'warn' in
options() but hadn't found a way to do this. I'm still searching
various
docs for any ideas, and it seems to be something that might be quite
straightforward. Any points/ideas are appreciated. Thanks!
-----Original Message-----
From: Jason Turner [mailto:jasont at indigoindustrial.co.nz]
Sent: Tuesday, April 30, 2002 12:23 PM
To: Boryeu Mao
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] how to trap any warnings from an R function
On Mon, Apr 29, 2002 at 12:43:56PM -0700, Boryeu Mao
wrote:> Within an user function, how are the warnings from an R function be
trapped> (such that some proper actions can be taken)?
One way is with try()
Cheers
Jason
--
Indigo Industrial Controls Ltd.
64-21-343-545
jasont at indigoindustrial.co.nz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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 Mon, Apr 29, 2002 at 12:43:56PM -0700, Boryeu Mao wrote:> Within an user function, how are the warnings from an R function be trapped > (such that some proper actions can be taken)?One way is with try() Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._