[R] Summary: Unexpected result of read.dbf

From: Susumu Tanimura <stanimura-ngs_at_umin.ac.jp>
Date: Fri 19 Aug 2005 - 20:32:55 EST


Hi there,

This is summary and patch for a bug in read.dbf, demonstrating in Message-Id: <20050818150446.697835cb.stanimura-ngs@umin.ac.jp>.

After consulting Rjpwiki, a cyber-community of R user in Japan, the cause was found, and the patch of solution was proposed.

Overflowing occurs when we use read.dbf for reading a dbf file having a field of longer signed integer. For example,

$ dbf2txt test.dbf
 #KEYCODE
 422010010
 42201002101
 42201002102
 42201002103
 42201002104
 422010060
 422010071
 422010072
 42201008001
 42201008002

The KEYCODE field is numeric type, 19 digits, and no decimal. You can create this file with OpenOffice.org Calc, txt2dbf, and so on. You also prepare a file of CSV format.

> library(foreign)

 > cbind(read.csv("test.csv"),read.dbf("test.dbf"))

        KEYCODE KEYCODE
 1 422010010 422010010

 2  42201002101        NA
 3  42201002102        NA
 4  42201002103        NA
 5  42201002104        NA

 6 422010060 422010060
 7 422010071 422010071
 8 422010072 422010072
 9  42201008001        NA
 10 42201008002        NA

This is not reproducible when the field has decimals like numeric type, 19 digits, and 5 decimals.

The patch written of Mr. Eiji Nakama is followed.

After adopting the patch, read.dbf works correctly.

> cbind(read.csv("test.csv"),read.dbf("test.dbf"))

       KEYCODE KEYCODE
1 422010010 422010010
2 42201002101 42201002101
3 42201002102 42201002102
4 42201002103 42201002103
5 42201002104 42201002104
6 422010060 422010060
7 422010071 422010071
8 422010072 422010072
9 42201008001 42201008001
10 42201008002 42201008002

--
Susumu Tanimura

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Aug 19 20:53:13 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:54 EST