Hi still yet again! I have the following code:> try(log(rnorm(25)),silent=TRUE)[1] -0.26396185 NaN NaN -0.13078069 -2.44997193 -2.15603971 NaN 0.94917495 0.07244544 NaN [11] -1.06341127 -0.42293099 -0.53769569 0.95134763 0.93403340 NaN -0.10502078 NaN 0.30283262 NaN [21] -0.11696872 -3.84122332 NaN NaN -0.12808690 Warning message: In log(rnorm(25)) : NaNs produced>I thought that putting the "silent = TRUE" would suppress the warnings, please. What should I do instead, please? Thanks, Edna Bell
> > try(log(rnorm(25)),silent=TRUE) > [1] -0.26396185 NaN NaN -0.13078069 -2.44997193 > -2.15603971 NaN 0.94917495 0.07244544 NaN > [11] -1.06341127 -0.42293099 -0.53769569 0.95134763 0.93403340 > NaN -0.10502078 NaN 0.30283262 NaN > [21] -0.11696872 -3.84122332 NaN NaN -0.12808690 > Warning message: > In log(rnorm(25)) : NaNs produced > > > > I thought that putting the "silent = TRUE" would suppress the > warnings, please. What should I do instead, please?The 'silent' argument to try supresses errors, not warnings. You can convert warnings to errors with options(warn=2), or ignore warnings with options(warn=-1). See ?options for more details. Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
On Tue, 29 Jul 2008, Edna Bell wrote:> Hi still yet again! > > I have the following code: > >> try(log(rnorm(25)),silent=TRUE) > [1] -0.26396185 NaN NaN -0.13078069 -2.44997193 > -2.15603971 NaN 0.94917495 0.07244544 NaN > [11] -1.06341127 -0.42293099 -0.53769569 0.95134763 0.93403340 > NaN -0.10502078 NaN 0.30283262 NaN > [21] -0.11696872 -3.84122332 NaN NaN -0.12808690 > Warning message: > In log(rnorm(25)) : NaNs produced >> > > I thought that putting the "silent = TRUE" would suppress the > warnings, please. What should I do instead, please?No, it supresses the error message (and you have no error here). Use suppressWarnings(). -- 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
"Edna Bell" <edna.bell01 at gmail.com> wrote:> Hi still yet again! > > I have the following code: > > > try(log(rnorm(25)),silent=TRUE) > [1] -0.26396185 NaN NaN -0.13078069 -2.44997193 > -2.15603971 NaN 0.94917495 0.07244544 NaN > [11] -1.06341127 -0.42293099 -0.53769569 0.95134763 0.93403340 > NaN -0.10502078 NaN 0.30283262 NaN > [21] -0.11696872 -3.84122332 NaN NaN -0.12808690 > Warning message: > In log(rnorm(25)) : NaNs produced > > > > I thought that putting the "silent = TRUE" would suppress the > warnings, please. What should I do instead, please?It's not a great idea to take logs of negative numbers. Better than supressing the resulting messages, you might try something like this:> a <- rnorm(25) > b <- log(ifelse(a < 0, NA, a))which gives this:> a[1] -0.04816269 -0.50745059 0.15229031 0.54735811 [5] -0.29896853 1.81854119 0.19462259 -0.48984075 [9] 0.63489288 1.47432484 1.15295160 0.75842227 [13] 0.07918115 1.04596643 1.31722543 -0.03614219 [17] 0.44072181 0.25358843 -0.49626405 -2.10954780 [21] -0.85815654 1.38983430 0.66592947 0.64700068 [25] -1.17829527> b[1] NA NA -1.88196666 -0.60265201 [5] NA 0.59803463 -1.63669302 NA [9] -0.45429898 0.38820015 0.14232526 -0.27651496 [13] -2.53601706 0.04494127 0.27552758 NA [17] -0.81934141 -1.37204269 NA NA [21] NA 0.32918453 -0.40657152 -0.43540794 [25] NA>See the help page for ifelse() for more information. -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement.