How can I use a DBF layer in an R script in QGIS?

For example, I can input a vector by using ##Layer=vector, and a CSV table with ##Table=table, but it will fail if the table is based on a DBF file.

I can export from DBF to CSV, but then I will loose the joins I have defined.

  • Not an R user but from a FAQ section, it mentions to download/install the foreign package which would allow you to use the read.dbf function. There's also some more information here which includes an example on how to read dbf files. Hope this is of some help!
    – Joseph
    Sep 3, 2015 at 9:58
  • Thanks for the links. They are useful for importing a DBF in R and I may use the articles for a workaround but I'm more interested in QGIS providing the data directly to the R environment through a ## command for example.
    – paul0207
    Sep 3, 2015 at 20:16

2 Answers 2


QGIS/Processing/R does not accept .dbf files. However there is a workaround that involves using the "foreign" package.

Create a script with a folder parameter and set its path to the folder where you stored your .dbf file. Then use this code to import the .dbf file into the R environment.

x <- read.dbf("your_file.dbf")

enter image description here

  • Thanks Filipe, the foreign library workaround works great.
    – paul0207
    Sep 18, 2015 at 21:31

(Posted this as an answer as it's too long for a comment. But atleast I can add an image!)

I think you may need to install the rpy extension for Python as mentioned in this post: Resources on using R in QGIS for R users?.

You should be able to install this extension using the OSGeo4W setup and selecting Advanced Install setting. Go through the options until you get to Select Packages. You can leave everything to Default if you don't care about other packages but in the search box, type rpy and you should get a Libs package with the rpy binding. Click the Skip message to change it:

rpy extension

Hope this helps!

  • Thanks Joseph for you additional comment. The Rpy library is another workaround worth to check.
    – paul0207
    Sep 18, 2015 at 21:33
  • @paul0207 - No worries buddy, glad you got it sorted!
    – Joseph
    Sep 21, 2015 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.