Skip to content

read.table with option dec=',' (PR#3532)

2 messages · Tony Plate, Brian Ripley

#
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:
#
x[<length-0>] <- list()

is intended to work, and did at one point in R-devel.  Unfortunately I 
added (p:1) at one point since ... it works again now.
On Tue, 22 Jul 2003 tplate@blackmesacapital.com wrote: