Error in library(sp) : there is no package called 'sp' - r

The sp package was installed using RStudio (through CRAN) but when R evaluates the code:
library(sp)
It throws an error
Error in library(sp) : there is no package called 'sp'
I noticed that it works for R versions 4.* but does not work for versions 3.*. What could be causing this?

If you first time to use 'sp', install.... :)
install.packages("sp")
library(sp)

Related

R Colab library error message: 'Error in library(package) : there is no package called ‘package’'

I'm trying to find a package that will let me add north arrows and scale bars to map plots in R.
I can see ggspatial and ggsn can both do this. I'm using colab and have been able to install and access all other packges and create maps succesfully. I can install both the gssn and geospatial package fine. But when I run 'library(package)' I get the same error whenever I try to import either package.
My code:
%load_ext rpy2.ipython
%%R
install.packages(c("ggplot2", "devtools", "dplyr", "stringr"))
install.packages(c("maps", "mapdata", "ggmap", "sf", "gssn")) # or "geospatial" in place of "gssn"
%%R
library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
library(gssn) # or deospatial in place of geospatial
All other packges install fine, but I get this error after the 'library(ggspatial)' or 'library(gssn)' lines, e.g with geospatial:
RInterpreterError: Failed to parse and evaluate line 'library(ggplot2)\nlibrary(ggmap)\nlibrary(maps)\nlibrary(mapdata)\nlibrary(ggspatial)\n'.
R error message: 'Error in library(ggspatial) : there is no package called ‘ggspatial’'
How do I fix this?

How to use function "get_data_structure"

I try to use the function "get_data_structure" but got an error as below.
Could anyone know how to fix it?
Thank you in advance
get_data_structure("DUR_D")
Error in data.frame(data_structure#concepts) :
trying to get slot "concepts" from an object (class "data.frame") that is not an S4 object
The problem appears to be a bug in the version of the OECD package on CRAN. If you install the development version, it works. First, close R and reopen a clean new session, then run this:
remotes::install_github("https://github.com/expersso/OECD")
library(OECD)
get_datasets()
get_data_structure("DUR_D")
remotes::install_github("https://github.com/expersso/OECD")
library(OECD)
dataset <- "DUR_D"
dstruc <- get_data_structure(dataset)
Try with get_dataset("DUR_D") i.e. without -s. as get_datasets() with -s will return a dataframe of available datasets.
It is a bug in the package OECD 0.2.5.
It works with the package version 0.2.4 which you can install from CRAN's archived package section (https://cran.r-project.org/src/contrib/Archive/OECD).
If you want to access the archived package version directly in R, use the following code:
devtools::install_version("OECD", version = "0.2.4", repos = "https://stat.ethz.ch/CRAN/")
Note that this requires the package 'devtools' to be installed.

knitr package loading error stringr

I get the following error:
1Error in library(stringr) :
Package 'stringr' version 1.2.0 cannot be unloaded
when loading the following packages in my knitr document:
library(checkpoint)
checkpoint("2017-01-01")
library(stringr)
library(plyr)
library(tidyr)
library(dplyr)
library(knitr)
library(readr)
library(readxl)
library(ggplot2)
library(scales)
library(ggthemes)
library(lubridate)
library(xtable)
library(zoo)
library(gridExtra)
when I remove stringr then I get the error:
Error in mutate_impl(.data, dots) : could not find function "str_sub"
...any ideas? I am using Mac OSX Mavericks. I copied the files over from a Windows 7 (where it worked) and I'm assuming that has something to do with it.
Thank you in advance!
There is a conflict due to the stringr package being newer (2017-02-18) than your checkpoint date of 2017-01-01.
You could clear the conflict by moving the date you use to something later, i.e.
checkpoint("2017-02-18") # or later
Alternatively, if you find you have mixed dependencies that rely on packages that were not all current on the same date, I would recommend having a look at packrat (link), which is designed for that purpose.

Error: isTRUE(gpclibPermitStatus()) is not TRUE

This question may be a duplicate of an earlier unanswered one. I still have the problem.
I am trying to use a zipcode shapefile and coming up with the following error:
tract <- readOGR(dsn = ".", layer = "cb_2013_us_zcta510_500k")
tract<-fortify(tract, region="GEOID10")
Error: isTRUE(gpclibPermitStatus()) is not TRUE
I have tried installing gpclib to fix this but then I get the following error:
install.packages("gpclib")
Installing package into ‘C:/Users/Nick/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘gpclib’
These will not be installed
Help?
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.
I ran into the same problem but the solution was slightly different than those listed above.
As mentioned by others, the issue is the dependency on gpclib, which is required by maptools.
However, after loading maptools, it provided the following message ...
> 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()
So rgeos can be used instead of gpclib. To resolve, I did the following ...
install.packages('rgeos', type='source')
install.packages('rgdal', type='source')
The reinstallation of rgdal removes the dependency on gpclib and points to rgeos.
Hope this is helpful.
I learned this answer elsewhere: I had to type
install.packages("gpclib", type="source")
and it worked just fine.

R could not find function "checkAtAssignment" while running rworldmap

I need your help with R not being able to run a function with rworldmap package.
When using rworldmap package in R and trying to 'joinCountryData2Map'
sPDF <- joinCountryData2Map (myframe, joinCode = "NAME", nameJoinColumn = "location", verbose = TRUE, suggestForFailedCodes = TRUE )
I get the following error:
Error in mapWithData#data <- cbind(mapWithData#data, dF[matchPosnsInUserData, :
could not find function "checkAtAssignment"
Calls: joinCountryData2Map
Execution halted
My guess is that R needs methods package, which I could not find for my R version.
Any suggestings why I 'could not find function "checkAtAssignment"'?
My R version is 3.0.2 Patched.
Using rworldmap package requires loading library(methods). I am writing it here because it was really not obvious.
Dunno what "R 3.0.2 Patched" means, but yes you are correct that somehow you don't have the methods package, which is included in the standard installation package. How about reinstalling R from the binaries or source tarball at CRAN -- that should solve your problem.

Resources