lucas@toulouse.inra.fr
2003-Jul-22 15:29 UTC
[Rd] read.table with option dec=',' (PR#3532)
Full_Name: Antoine Lucas Version: 1.7.0 (2003-04-16) OS: Linux Submission from: (NULL) (193.51.197.253) I have a problem using read.table: If in a dataframe, we have a string containing a dot, write.table will not write any file while using option "dec=','". Example> m <- "1.5" > write.table(m,dec=',')Error in if (n%%nrowv == 0) value <- value[rep(1:nrowv, length = n), , : missing value where TRUE/FALSE needed In addition: Warning messages: 1: no finite arguments to min; returning Inf 2: no finite arguments to max; returning -Inf Whereas the contrary write the table:> m <- "1,5" > write.table(m,dec='.')"x" "1" "1,5" Best regards Antoine Lucas -- Antoine Lucas INRA, Unité de biométrie et | Tel 05 61 28 53 34 intelligence artificielle | Fax 05 61 28 53 35 http://genopole.toulouse.inra.fr/~lucas
tplate@blackmesacapital.com
2003-Jul-22 17:26 UTC
[Rd] read.table with option dec=',' (PR#3532)
The problem appears to occur in the following expression from write.table(): x[num] <- lapply(x[num], function(z) gsub("\\.", ",",as.character(z))) which gives an error when 'num' has length zero (for what it's worth, the RHS evaluated to list()). The error reported occurs when dec= is supplied to write.table() and the table has no numeric columns. Data frame column assignment does not appear able to handle the case where the index has zero length, as in the following example > x <- data.frame(x="1.5") > num <- numeric(0) > x[num] <- list() Error in if (n%%nrowv == 0) value <- value[rep(1:nrowv, length = n), , : missing value where TRUE/FALSE needed In addition: Warning messages: 1: no finite arguments to min; returning Inf 2: no finite arguments to max; returning -Inf > traceback() 2: "[<-.data.frame"(*tmp*, num, value = list()) 1: "[<-"(*tmp*, num, value = list()) > Possible fixes are to either guard the expression in write.table() with 'if (length(num))' or to change "[<-.data.frame"() to handle this case. (I note that S-plus 6.1 under Windows and R1.6.2 under Windows also generate an error with this type of data frame assignment, so it does not appear to be a new bug with data frame assignment, and is probably best fixed with the simple change to write.table()) -- Tony Plate At Tuesday 03:29 PM 7/22/2003 +0200, lucas@toulouse.inra.fr wrote:>Full_Name: Antoine Lucas >Version: 1.7.0 (2003-04-16) >OS: Linux >Submission from: (NULL) (193.51.197.253) > > >I have a problem using read.table: > >If in a dataframe, we have a string containing a dot, write.table >will not write any file while using option "dec=','". > >Example > > > m <- "1.5" > > write.table(m,dec=',') >Error in if (n%%nrowv == 0) value <- value[rep(1:nrowv, length = n), , : > missing value where TRUE/FALSE needed >In addition: Warning messages: >1: no finite arguments to min; returning Inf >2: no finite arguments to max; returning -Inf > >Whereas the contrary write the table: > > m <- "1,5" > > write.table(m,dec='.') >"x" >"1" "1,5" > > >Best regards > >Antoine Lucas > >-- >Antoine Lucas >INRA, Unité de biométrie et | Tel 05 61 28 53 34 >intelligence artificielle | Fax 05 61 28 53 35 >http://genopole.toulouse.inra.fr/~lucas > >______________________________________________ >R-devel@stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
lucas@toulouse.inra.fr writes:> Full_Name: Antoine Lucas > Version: 1.7.0 (2003-04-16) > OS: Linux > Submission from: (NULL) (193.51.197.253) > > > I have a problem using read.table:????> If in a dataframe, we have a string containing a dot, write.table > will not write any file while using option "dec=','". > > Example > > > m <- "1.5" > > write.table(m,dec=',') > Error in if (n%%nrowv == 0) value <- value[rep(1:nrowv, length = n), , : > missing value where TRUE/FALSE needed > In addition: Warning messages: > 1: no finite arguments to min; returning Inf > 2: no finite arguments to max; returning -Inf > > Whereas the contrary write the table: > > m <- "1,5" > > write.table(m,dec='.') > "x" > "1" "1,5"Wrong diagnosis:> m <- data.frame(1.5,"1.5") > write.table(m,dec=',')"X1.5" "X.1.5." "1" 1,5 "1.5"> m <- data.frame("a","b") > write.table(m,dec=',')Error in if (n%%nrowv == 0) value <- value[rep(1:nrowv, length = n), , : missing value where TRUE/FALSE needed In addition: Warning messages: 1: no finite arguments to min; returning Inf 2: no finite arguments to max; returning -Inf The problem is unrelated to whether or not there are strings with dots in. The real reason is that you have no numeric columns. If you don't have any numeric colums, then you can just leave out the dec argument since it is not supposed to do anything with character columns. The code in write.table is conditional on dec != "."; that's why the thing is unsymmetric in dot and comma. We should probably treat these borderline cases more gracefully though. Possibly even at the data frame indexing level: it boils down to> x[numeric(0)] <- list()Error in if (n%%nrowv == 0) value <- value[rep(1:nrowv, length = n), , : missing value where TRUE/FALSE needed In addition: Warning messages: 1: no finite arguments to min; returning Inf 2: no finite arguments to max; returning -Inf and I suppose we might just treat this as a no-op. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907