Question: I am receiving a sporadic error message with importShapefile in PBSmapping (version 2.63.37) in RStudio (0.97.318), running R version 2.15.2, platform: i386-w64-mingw32/i386 (32-bit). I also received the error while running previous versions of R and RStudio.

```
> ST6 = importShapefile("Data/pvi_stat_2002_utm.shp", projection="UTM", readDBF = TRUE)
Error in 1:nrow(dbf) : argument of length 0

> traceback()
2: cbind(1:nrow(dbf), dbf)
1: importShapefile("Data/pvi_stat_2002_utm.shp", projection = "UTM",readDBF = TRUE)

```

I only receive this error occasionally - perhaps 1 in every 10 times that I run the code. But once the error occurs in a session, it occurs repeatedly and will not successfully implement the command until I have closed R completely and reopened it. On one occasion I had to reboot the computer for it to work, as successive reopening of R did not help.

I thought it might be a memory issue but sometimes I will get the error when no objects are in the workspace. And usually the code runs fine even if I have large objects loaded. In response to the error I have removed all objects from the workspace and even followed with gc(), but to no avail.

This is the only shapefile with which I have received the error but as it is the only one that I use with regularity and since I can not predict when the error will occur, my efforts with other shapefiles are inconclusive. Not sure about uploading a shapefile to Stack Overflow. The zipped file is about 9MB.

Answer: 
Have a look in the folder where your shapefile is. Is there actually a `.dbf` file? If there is, it sounds like it is empty or corrupted, or misnamed. Are you expecting your shapefile to have polygons with attributes. Can you try `importShapefile(... readDBF = FALSE )`? Maybe you can make our data available through a dropbox link or something?

Alternatively have you tried `rgdal:::readOGR` or, my personal favourite, `maptools:::readShapePoly()`. I personally find `readShapePoly()` to be extremely robust and there are methods for coercing a `SpatialPolygonsDataFrame` from `sp` to a `PolySet` from PBS.

If you really must use PBS have you tried...

```
require( maptools )
require( sp )
myshp <- readShapePoly("Data/pvi_stat_2002_utm")
myshpPBS <- SpatialPolygons2PolySet( myshp )

```

I am assuming that there is a `.prj` file with your shapefile, describing the projection information?
I'm using R-3.0.1 and PBS Mapping 2.66.53 with the NAVO Divisions shapefile from <http://www.nafo.int/about/overview/gis/Divisions.zip>. On Windows 7 x86\_64 and OS X Snow Leopard (using macports R built for x86\_64), the .dbf is being read properly, but it
sometimes fails using RHEL 5.9:

```
> library("PBSmapping", lib.loc="/home/gwhite/R/x86_64-unknown-linux-gnu-library/3.0")

-----------------------------------------------------------
PBS Mapping 2.66.53 -- Copyright (C) 2003-2013 Fisheries and Oceans Canada

[...]
-----------------------------------------------------------

> library("rgeos", lib.loc="/home/gwhite/R/x86_64-unknown-linux-gnu-library/3.0")
 rgeos version: 0.2-19, (SVN revision 394)
 GEOS runtime version: 3.3.8-CAPI-1.7.8 
 Polygon checking: TRUE 

> layer='Divisions'
> divs = importShapefile(layer, projection='LL')
Error in 1:nrow(dbf) : argument of length 0

```

Using `readDBF=F` does allow the shapefile data to be read:

```
> divs = importShapefile(layer, projection='LL', readDBF=F)

```

So far, `importShapefile()` has been working in a freshly started R session.