Skip to Content

read.dbf {foreign}

Read a DBF File
Package: 
foreign
Version: 
0.8-59

Description

The function reads a DBF file into a data frame, converting character fields to factors, and trying to respect NULL fields.

The DBF format is documented but not much adhered to. There is is no guarantee this will read all DBF files.

Usage

read.dbf(file, as.is = FALSE)

Arguments

file
name of input file
as.is
should character vectors not be converted to factors?

Details

DBF is the extension used for files written for the ‘XBASE’ family of database languages, ‘covering the dBase, Clipper, FoxPro, and their Windows equivalents Visual dBase, Visual Objects, and Visual FoxPro, plus some older products’ (http://www.clicketyclick.dk/databases/xbase/format/). Most of these follow the file structure used by Ashton-Tate's dBase II, III or 4 (later owned by Borland).

read.dbf is based on C code from http://shapelib.maptools.org/ which implements the ‘XBASE’ specification. It can convert fields of type "L" (logical), "N" and "F" (numeric and float) and "D" (dates): all other field types are read as-is as character vectors. A numeric field is read as an R integer vector if it is encoded to have no decimals, otherwise as a numeric vector. However, if the numbers are too large to fit into an integer vector, it is changed to numeric. Note that is possible to read integers that cannot be represented exactly even as doubles: this sometimes occurs if IDs are incorrectly coded as numeric.

Values

A data frame of data from the DBF file; note that the field names are adjusted to use in R using make.names(unique=TRUE).

There is an attribute "data_type" giving the single-character dBase types for each field.

References

http://shapelib.maptools.org/.

The Borland file specification via http://www.wotsit.org, currently at http://www.wotsit.org/list.asp?fc=6.

Note

Not to be able to read a particular ‘DBF’ file is not a bug: this is a convenience function especially for shapefiles.

See Also

write.dbf

Examples

x <- read.dbf(system.file("files/sids.dbf", package="foreign")[1])
str(x)
summary(x)

Author(s)

Nicholas Lewin-Koh and Roger Bivand; shapelib by Frank Warmerdam

Documentation reproduced from package foreign, version 0.8-59. License: GPL (>= 2)