shiny
shiny

Reputation: 3502

import .dbf into RStudio: failed on DBF filefseek (-2147207979)

I'm trying to import .dbf file into RStudio.

This file is the attribute table of a shapefile that I exported as .dbf. You can find the .dbf file in this link

I tried importing it as below

library(foreign)
df <- read.dbf("5layers1.dbf")

I got errors (below) and RStudio crashed so I couldn't get sessionInfo(). enter image description here

Any suggestions how to import this large .dbf file into RStudio will be highly appreciated.

Upvotes: 2

Views: 3661

Answers (3)

jsta
jsta

Reputation: 3393

Similar to the OP, I found that foreign::read.dbf crashed my session. However I was able to use the rio package without any problems:

df <- rio::import("5layers1.dbf")

https://github.com/leeper/rio

Upvotes: 1

Patrik_P
Patrik_P

Reputation: 3200

For me read.dbf() didn't work neither and the files are usually too big to open it in excel to convert them into something more usable. I find a better way to read in .dbf files is to use the dbf ODBC Driver distributed under Windows (usually only 32-bit version), given you operate under Windows, and create a connection together with the RODBC and ultimately access the data as in the usual way you connect to a database. Now, one would need to use the 32-bit version of R so it´s compatible with the driver architecture, but R comes with both 32 and 64 bit versions.

Upvotes: 1

and-bri
and-bri

Reputation: 1664

I suggest to save it as a csv-file (I did this with LibreOffice in one or two hours and use ; as a separator). After you can import it to R like this:

dat <- readLines("5layers1.csv")

li <- strsplit(dat, ";")
num <- as.numeric(unlist(lapply(li, `[[`, 100)))

boxplot(num, main=unlist(strsplit(dat[1], ";"))[100])
mtext(side=3, text=paste("n = ", length(num), sep=""))

Its really a big file! You will have a lot of fun with this! I'm not sure if R is the tool for this job. I use a Tinkpad T430 with 8GB Ram and it need 2min for run this five lines to make this boxplot, which present one of the 179 attributes of your dbf-file:

enter image description here

Upvotes: 1

Related Questions