similar to: using as.numeric() without generating warning message

Displaying 20 results from an estimated 20000 matches similar to: "using as.numeric() without generating warning message"

2008 Dec 07
4
Finding the first value without warning in a loop
Dear R useRs, with the following piece of code i try to find the first value which can be calculated without warnings `test` <- function(a) { repeat { ## hide warnings suppressWarnings(log(a)) if (exists("last.warning", envir = .GlobalEnv)) { a <- a + 0.1 ## clear existing warnings rm("last.warning", envir = .GlobalEnv) }
2015 Sep 10
2
Using IDs to suppress specific messages and warnings
The suppressMessages and suppressWarnings functions currently suppress all the message or warnings that are generated by the input expression. The ability to suppress only specific messages or warnings is sometimes useful, particularly for cases like file import where there are lots of things that can go wrong. Suppressing only messages that match a regular expression has rightly been rejected
2009 Jun 04
1
how to tell if as.numeric succeeds?
Suppose I have a vector of strings. I'd like to convert this to a vector of numbers if possible. How can I tell if it is possible? as.numeric() will issue a warning if it fails. Do I need to trap this warning? If so, how? In other words, my end goal is a function that takes a vector of strings and returns either a numeric vector or the original vector. Assuming this doesn't already
2007 Oct 17
1
ignorable warnings of as.numeric: NAs introduced by coercion
Warnings are a good thing and can help to find errors in data. But with newer R versions I get more and more warnings which I would like to suppress in defined circumstances. In the manual of as.numeric() is noticed: as.numeric(c("-.1"," 2.7 ","B")) # (-0.1, 2.7, NA) + warning If I know that my data contains characters and if I would like that they will be
2016 Jul 04
2
cat() in proc.time?
Does anyone know if there's a reason that proc.time() uses cat() rather than message() to print the output when there has been an error in the process of timing? line 31 of time.R, https://github.com/wch/r-source/blob/e5b21d0397c607883ff25cca379687b86933d730/src/library/base/R/time.R#L31 on.exit(cat("Timing stopped at:", ppt(proc.time() - time), "\n")) This means that
2017 Dec 15
1
cannot destroy connection (?) created by readLines in a tryCatch
Thanks for tracking this down. Yeah, I should use suppressWarnings(), you are right. Although, readLines() might throw another warning, e.g. for incomplete last lines, and you don't necessarily want to suppress that. TBH I am not sure why that warning is given: ? con <- file(tempfile()) ? open(con) Error in open.connection(con) : cannot open the connection In addition: Warning message: In
2008 Jul 01
2
ignore warning messages?
Hi All, I'm working with R and want to ignore the warning messages given, is there a way to stop R from giving out warning messages any more? an example: tt = "test" as.numeric(tt) would give me the following message: [1] NA Warning message: NAs introduced by coercion I decide to ignore the warning message for now and don't want it to show any more, can someone help?
2017 Jun 12
2
Bucle for que se salte los errores
He encontrado la respuesta. EL ejemplo que puse era trivial, ya que es obvio que if(i ==0) entonces next, pero me referia a sin saber si va a ser error el modelo o no. Para esto he encontrado la solución for(i in -3:3){ tryCatch({ z<-1/i > z<-z*z > modelo<-lm(z~1) }, error=function(e){print("es un error"}) } Gracias de todas maneras!!!!! Jesús
2017 Dec 14
4
cannot destroy connection (?) created by readLines in a tryCatch
On Thu, Dec 14, 2017 at 7:56 PM, Gabriel Becker <gmbecker at ucdavis.edu> wrote: > Gabor, > > You can grab the connection and destroy it via getConnection and then a > standard close call. Yeah, that's often a possible workaround, but since this connection was opened by readLines() internally, I don't necessarily know which one it is. E.g. I might open multiple
2008 May 14
2
The try() function with read.delim().
I have written a function which reads data from files using read.delim (). The names of these files are complicated and are built using arguments to the wrapper function. Since the files in question may or may not exist, I thought to enclose the read.delim() call in a try(): file <- <complicated expression> temp <- try(read.delim(file)) if(inherits(temp,"try-error")) {
2006 Sep 29
2
Warning: a final empty element has been omitted
How can I suppress this warning? > options(warn = -10) > list(1,2,3,) Warning: a final empty element has been omitted the part of the args list of 'list' being evaluated was: (1, 2, 3, ) [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 > suppressWarnings(list(1,)) Warning: a final empty element has been omitted the part of the args list of 'list' being evaluated was: (1, )
2017 Sep 14
1
Print All Warnings that Occurr in All Parallel Nodes
Dear R Users, I have developed the following code for importing a series of zipped CSV by parallel computing. My problems are that: A) Some ZIP Files (Which contain CSVs inside) are corrupted, and cannot be opened. B) After executing parRapply I can only see the last.warning variable error, for knowing which CSV have failed in each node, but I cannot see all warnings, only 1 at a time. So: *
2016 Jul 17
1
cat() in system.time() ?
On Fri, 15 Jul 2016, Martin Maechler wrote: > Hi Ben (and everyone else), > > as this did not attract attention yet, let me start > >>>>>> Ben Bolker <bbolker at gmail.com> >>>>>> on Mon, 4 Jul 2016 11:49:40 -0400 writes: > > > Does anyone know if there's a reason that proc.time() uses cat() > > rather than
2011 Apr 04
2
how to handle no lines in input with pipe()
This has to do with using pipe() and grep and read.csv() I have a .csv file that I grep using pipe() and read.csv() as follows: read.csv(pipe('grep foo bar.csv')) However, is there a way to have this command run when for example, there is no "foo" text in the bar.csv file? I get an error message (appropriately): Error in read.table(file = file, header = header, sep = sep,
2007 Feb 19
2
"try"ing to understand condition handling
I'm confused by the page documenting tryCatch and friends. I think it describes 3 separate mechanisms: tryCatch (in which control returns to the invoking tryCatch), withCallHandlers (in which control goes up to the calling handler/s but then continues from the point at which signalCondition() was invoked), and withRestarts (I can't tell where control ends up). For tryCatch the docs say
2007 Jan 31
5
Quick Question about R
Hello, Is there a way to convert a character to a number with out getting a warning? I have a vector that has both numbers and letters in it and I need to convert it to only numbers. At the moment I'm using as.numeric but it is generating a warning when it converts a letter. Is there another function out there that will do what I need or is there a way to turn off the warnings as I
2023 Mar 03
2
transform.data.frame() ignores unnamed arguments when no named argument is provided
>>>>> Gabriel Becker >>>>> on Thu, 2 Mar 2023 14:37:18 -0800 writes: > On Thu, Mar 2, 2023 at 2:02?PM Antoine Fabri > <antoine.fabri at gmail.com> wrote: >> Thanks and good point about unspecified behavior. The way >> it behaves now (when it doesn't ignore) is more >> consistent with data.frame() though so I
2011 Jul 29
2
converting factor to numeric gives "NAs introduced by coercion"
Hi, I have a dataframe that I imported from a .txt file by: skogTemp <- read.delim2("Skogaryd_shoot_data.txt", header=TRUE, fill=TRUE) and the data are factors, how can avoid factors from the beginning? Although the file contains both characters and numbers. I tried to convert some of the columns from factor to numeric and as I understood it you can not use only as.numeric but
2003 Feb 20
2
is.numeric
Hi, I have a vector, which contains both strings and numbers, e.g. > foo <- c("str1",1234,"str2",0.9876) I want to know if a distinct element of the vector is a string or a number and took "is.numeric", but > is.numeric(foo[2]) [1] FALSE because R treats the numbers in a mixed vectors as strings: > foo [1] "str1" "1234"
2016 Dec 08
1
require(..., quietly=TRUE) does not suppress warning
Well, I'm getting a warning (not an error) when the package doesn't exist. I interpreted "most often" to mean that suppressing warnings/errors is why you'd most often use this argument, as most packages don't emit startup messages. And technically there isn't a problem with attaching the package, since we don't even try to attach packages that don't exist.