[R] Import Visual FoxPro (.dbf)

Andy Choens andy.choens at gmail.com
Mon May 11 15:23:06 CEST 2009

I have a large series of Visual FoxPro (.dbf) files that I want to
convert to a plain text (.csv) file. I wrote a quick script to do all of
this for me. With a little tweaking it seemed to work like a charm. But,
when I looked at my newly created text files carefully, I discovered a
problem. Every single file produced by my script had a few extra columns
in it. 

To better understand this, I imported a single file. Here are my

> library(foreign)
> temp.df <- read.dbf("Activity.dbf")
ilp.dbc changed to: X.ilp.dbc
Field name:  changed to: X
Field name:  changed to: X.1
Field name:  changed to: X.2
Field name:  changed to: X.3
Field name:  changed to: X.4
Field name:  changed to: X.5
Field name:  changed to: X.6

Based on the table definitions I received from the state, none of these
tables have a column called ilp.dbc. When I open these same .dbf files
in OpenOffice.org, individually, I do not see these columns. When I look
at the temp.df in R, these mystery columns are all empty. Otherwise, the
data appears to be fine.

I looked at ?read.dbf and I did not see any options to play with that
would seem to help.

At the moment, I have a work-around in my script that prevents these
extra columns from being written to the csv files, but I am curious to
learn what I am doing wrong. The problem may be entirely of my own

Most of the info in these files is protected by HIPAA, which limits my
ability to provide example files. If anyone really wants one, I can look
to see if there are any files that I can release. Or I can try deleting
all of the info and see if the problem persists.

Version Information:
r-project: 2.8.1 
foreign:   0.8.30-1 
Ubuntu:    9.04 (32-bit)

Thanks for any thoughts.

This is the price and the promise of citizenship.
    - Barack Obama

More information about the R-help mailing list