0

This I know is a fairly common error with gpclib but I feel I've tried a lot of options and going around in circles. I come up against this issue when using 'fortify' to create a data frame from a UK local authority shapefile, so that eventually I can create a choropleth using ggplot2.

After trying to install gpclib package in the usual way I then tried to install from source:

install.packages("gpclib", type = "source")

Which says unsuccessfully unpacked but then 'ERROR: compilation failed for package 'gpclib'. I then read somewhere you need to have R Tools installed so I tried that but to no avail, same error. I then tried changing the order in which you attach rgeos and maptools because apparently this matters and this didn't work.

My code is dead simple and yet I'm at a brick wall early in the project.

Are there any other things to try to get gpclib installed?

Many thanks in anticipation, my code is below. Henry

install.packages("rgdal")
library(rgdal)
install.packages("maptools")
library(maptools)
install.packages("rgeos")
library(rgeos)
myshape <- readShapeSpatial("infuse_ward_lyr_2011.shp")
myshape2 <- readShapeSpatial("infuse_dist_lyr_2011.shp")
plot(myshape)
plot(myshape2)
install.packages("ggplot2")
library(ggplot2)
str(myshape2)
myshape2frame <- fortify(myshape2, region="name")
install.packages("gpclib", type = "source")
library(gpclib)
gpclibPermit()
gpclibPermitStatus()
Henry Dark
  • 11
  • 3
  • Not sure if this will help with your problem, but to install a package from source you also have to set `repos` to `NULL`. Check here: http://stackoverflow.com/questions/1474081/how-do-i-install-an-r-package-from-source – C_Z_ Jul 25 '16 at 17:23
  • Thanks for your reply; unfortunately trying repos = NULL I get the following Warning: invalid package 'gpclib' Error: ERROR: no packages specified – Henry Dark Jul 25 '16 at 17:37
  • You have to give it the path to the downloaded package – C_Z_ Jul 25 '16 at 17:42

1 Answers1

1

For anyone in future with this problem I solved this.

I knew I had to install R Tools but what I didn't know was that it's essential to have the location of R Tools in your Path.

I didn't want to permanently set the path so I did so within R using:

pathRtools <- paste(c("c:\\Rtools\\bin",
"c:\\Rtools\\MinGW_64\\bin",
"c:\\MiKTeX\\miktex\\bin",
"c:\\R\\bin\\i386",
"c:\\windows",
"c:\\windows\\system32"), collapse=";")
Sys.setenv(PATH=paste(pathRtools,Sys.getenv("PATH"),sep=";"))

Please see the following post for details

Install R package from source, without changing PATH (Windows)

Community
  • 1
  • 1
Henry Dark
  • 11
  • 3