[R] A file with extension .sdb in a codebook section of a large database from a survey?

Marc Schwartz marc_schwartz at me.com
Thu Mar 25 23:35:49 CET 2010


On Mar 25, 2010, at 4:58 PM, Douglas Bates wrote:

> Thanks very much, Marc.
> 
> So did you really read 110 pages of the User Guide to find this out or
> did you do something more clever?

You are welcome Doug.

Nah...not so much clever as persistent. 

I actually started by Googling for the file extension, which led me to the possibility of anything from SQLite to OO.org's Base to a plethora of other possibilities, none of which really helped. There are a lot of 'file extension' references online. I actually tried to open one of the files with OO.org, but of course, no joy.

I then posited that I should follow the usual advice of RTFM, so I opened the PDF User Guide at the site in Preview and searched for 'sdb' in the file, which led me right to the relevant page. I suspected that someplace they might describe the files that they release. If not in that PDF, one of the others.

So then I figured that I would try read.dbf() hoping that might work, which it did not. That was puzzling, if these are standard dBase files. So I decided to look at the code for the function to see if anything was obvious. The R code calls .Call(Rdbfread, ...), so I went to the C source.

I looked at the C source code for Rdbfread() at https://svn.r-project.org/R-packages/trunk/foreign/src/Rdbfread.c. That in turn led me to DBFOpen() in https://svn.r-project.org/R-packages/trunk/foreign/src/dbfopen.c, where it became clear that function appears to be hard coded to open files with a .dbf extension only. It actually parses the basename of the file passed from the R function and then re-appends '.DBF', before opening the file.

Thus, changing the '.sdb' to '.dbf' worked. I am not sure that it is explicit in the help for read.dbf() that the only file extension allowed is .dbf, as opposed to more generally referring to a dBase format file.

Regards,

Marc

<snip>



More information about the R-help mailing list