How to turn gpclibPermit() to TRUE
I've struggled with the gpclibPermit
issue myself. You don't provide a reproducible example, but I am guessing that you are having a sesion like this:
library(maptools)
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry computations in maptools depend
on gpclib, which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
> gpclibPermitStatus()
[1] FALSE
> gpclibPermit()
[1] FALSE
> gpclibPermitStatus()
[1] FALSE
At this point it helps to look at what gpclibPermit
and gpclibPermitStatus
actually do:
> gpclibPermit
function ()
{
if ("gpclib" %in% .packages(all.available = TRUE))
assign("gpclib", TRUE, envir = .MAPTOOLS_CACHE)
if (gpclibPermitStatus())
warning("support for gpclib will be withdrawn from maptools at the next major release")
gpclibPermitStatus()
}
<environment: namespace:maptools>
> gpclibPermitStatus
function ()
get("gpclib", envir = .MAPTOOLS_CACHE)
<environment: namespace:maptools>
That is, you can't give maptools
the permission to use gpclib
unless you have the package gpclib
installed.
install.packages("gpclib")
library(maptools)
Loading required package: sp
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry computations in maptools depend on gpclib, which has a restricted licence. It is disabled by default; to enable gpclib, type gpclibPermit()
> gpclibPermit()
[1] TRUE
Warning message:
In gpclibPermit() :
support for gpclib will be withdrawn from maptools at the next major release
> gpclibPermitStatus()
[1] TRUE
Error: isTRUE(gpclibPermitStatus()) is not TRUE
You can look at Hadley's master file for ggplot2/R/fortify-spatial.r. Based on this outside link, my understanding is that lines 31–34 (in it's current form) used to read something like
# Union together all polygons that make up a region
try_require(c("gpclib", "maptools"))
unioned <- unionSpatialPolygons(cp, invert(polys))
So back then one way to attack the problem was to turn on the license
library(rgdal)
library(maptools)
if (!require(gpclib)) install.packages("gpclib", type="source")
gpclibPermit()
As @rcs, @Edzer Pebesma, and this answer mention, rgeos
should resolve the issue for more recent installations.
gpclibPermit() is FALSE, cannot install gpclib
"Extract[ing] to library folder" is not the correct way to install a source package (the .tar.gz you downloaded). Inside R
execute
install.packages(path_to_file, repos = NULL, type="source")
More details and approaches can be found at How do I install an R package from source?
Converting spatial polygon to regular data frame without use of gpclib tools
You need to also install the rgeos
package. When maptools
is loaded and rgeos
is not installed, the following message is shown:
> require("maptools")
Loading required package: maptools
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry
computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
When fortify
is called with a region
argument (as it is in the example you linked to), then some "polygon geometry computations" need to be done. If rgeos
is not available, and gpclib
is not permitted, it will fail.
tract_choropleth for NY data
The error is due to gpclibPermitStatus()
returning FALSE.
Unfortunately, this is a common error that comes up when working with choroplethr. I once gave a lengthy answer to the question here.
The short answer is to type the following:
install.packages("gpclib")
library(maptools)
gpclibPermit()
Related Topics
Partially Color Histogram in R
How to Update a Shiny Fileinput Object
Convert Hours:Minutes:Seconds to Minutes
Generating Multiple Plots in Ggplot by Factor
How to Display Emojis in Ggplot2 Using Emo Package in R
Got Message Unable to Load Shared Object Stats.So When R Starts
Convert Quarter/Year Format to a Date
Reverse and Change Limit of Axis
Aggregating All Unique Values of Each Column of Data Frame
Handling Errors Before Warnings in Trycatch
How to Plot a Heat Map on a Spatial Map
Display HTML File in Shiny App
Coloring Boxplot Outlier Points in Ggplot2
Subset Rows According to a Range of Time
Legends for Multiple Fills in Ggplot
Cbind: How to Have Missing Values Set to Na
Existing Function for Seeing If a Row Exists in a Data Frame