Learn R Programming

foreign (version 0.8-11)

write.dbf: Write a DBF File

Description

The function tries to write a data frame to a DBF file.

Usage

write.dbf(dataframe, file, factor2char = TRUE)

Arguments

dataframe
a data frame object.
file
a file name to be written to.
factor2char
logical, default TRUE, convert factor columns to character: otherwise they are written as the internal integer codes.

Value

  • Invisible NULL.

Details

Dots in column names are replaced by underlines in the DBF file, and names are truncated to 11 characters.

Only vector columns of classes "logical", "numeric", "integer", "character", "factor" and "Date" can be written. Other columns should be converted to one of these. Maximum precision (number of digits including minus sign and decimal sign) for numeric is 19 - scale (digits after the decimal sign) which is calculated internally based on the number of digits before the decimal sign.

References

http://shapelib.maptools.org/

See Also

read.dbf

Examples

Run this code
str(warpbreaks)
try1 <- paste(tempfile(), ".dbf", sep = "")
write.dbf(warpbreaks, try1, factor2char = FALSE)
in1 <- read.dbf(try1)
str(in1)
try2 <- paste(tempfile(), ".dbf", sep = "")
write.dbf(warpbreaks, try2, factor2char = TRUE)
in2 <- read.dbf(try2)
str(in2)
unlink(c(try1, try2))
<testonly>DF <- data.frame(a=c(1:3, NA), b=c(NA, rep(pi, 3)),
                 c=c(TRUE,NA, FALSE, TRUE), d=c("aa", "bb", NA, "dd"),
                 e=I(c("a1", NA, NA, "a4")))
DF$f <- as.Date(c("2001-01-01", NA, NA, "2004-10-26"))
str(DF)
write.dbf(DF, try2)
in2 <- read.dbf(try2)
str(in2)
unlink(try2)</testonly>

Run the code above in your browser using DataLab