ggspatial
ggspatial copied to clipboard
'Error in library(ggspatial) : there is no package called ‘ggspatial’
Can't load this package
my code:
install.packages(c("ggplot2", "devtools", "dplyr", "stringr"))
install.packages(c("maps", "mapdata", "ggmap", "sf", "ggspatial"))
library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
library(ggspatial)
throws error: RInterpreterError: Failed to parse and evaluate line 'library(ggsn)\n'. R error message: 'Error in library(ggsn) : there is no package called ‘ggspatial’'
This happens on google colab, and R studio (version 4.0.2 (2020-06-22)).
Full eror from colab here: WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: Error in library(ggspatial) : there is no package called ‘ggspatial’
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: In addition: WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: Warning messages:
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: 1: WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: In install.packages("ggspatial") : WARNING:rpy2.rinterface_lib.callbacks:R[write to console]:
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: installation of package ‘units’ had non-zero exit status
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: 2: WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: In install.packages("ggspatial") : WARNING:rpy2.rinterface_lib.callbacks:R[write to console]:
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: installation of package ‘sf’ had non-zero exit status
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: 3: WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: In install.packages("ggspatial") : WARNING:rpy2.rinterface_lib.callbacks:R[write to console]:
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: installation of package ‘ggspatial’ had non-zero exit status
Error in library(ggspatial) : there is no package called ‘ggspatial’
RRuntimeError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/rpy2/ipython/rmagic.py in eval(self, code) 267 # Need the newline in case the last line in code is a comment. --> 268 value, visible = ro.r("withVisible({%s\n})" % code) 269 except (ri.embedded.RRuntimeError, ValueError) as exception:
10 frames /usr/local/lib/python3.7/dist-packages/rpy2/robjects/init.py in call(self, string) 437 p = rinterface.parse(string) --> 438 res = self.eval(p) 439 return conversion.rpy2py(res)
/usr/local/lib/python3.7/dist-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 198 return (super(SignatureTranslatedFunction, self) --> 199 .call(*args, **kwargs)) 200
/usr/local/lib/python3.7/dist-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 124 new_kwargs[k] = conversion.py2rpy(v) --> 125 res = super(Function, self).call(*new_args, **new_kwargs) 126 res = conversion.rpy2py(res)
/usr/local/lib/python3.7/dist-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs) 44 def _(*args, **kwargs): ---> 45 cdata = function(*args, **kwargs) 46 # TODO: test cdata is of the expected CType
/usr/local/lib/python3.7/dist-packages/rpy2/rinterface.py in call(self, *args, **kwargs) 679 if error_occured[0]: --> 680 raise embedded.RRuntimeError(_rinterface._geterrmessage()) 681 return res
RRuntimeError: Error in library(ggspatial) : there is no package called ‘ggspatial’
During handling of the above exception, another exception occurred:
RInterpreterError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2357 with self.builtin_trap: 2358 args = (magic_arg_s, cell) -> 2359 result = fn(*args, **kwargs) 2360 return result 2361
/usr/local/lib/python3.7/dist-packages/IPython/core/magic.py in
/usr/local/lib/python3.7/dist-packages/rpy2/ipython/rmagic.py in R(self, line, cell, local_ns) 781 if not e.stdout.endswith(e.err): 782 print(e.err) --> 783 raise e 784 finally: 785 if self.device in ['png', 'svg']:
/usr/local/lib/python3.7/dist-packages/rpy2/ipython/rmagic.py in R(self, line, cell, local_ns) 761 return_output = False 762 else: --> 763 text_result, result, visible = self.eval(code) 764 text_output += text_result 765 if visible:
/usr/local/lib/python3.7/dist-packages/rpy2/ipython/rmagic.py in eval(self, code) 271 warning_or_other_msg = self.flush() 272 raise RInterpreterError(code, str(exception), --> 273 warning_or_other_msg) 274 text_output = self.flush() 275 return text_output, value, visible[0]
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’'
Hmm...do you get the output of install.packages("ggspatial")? My guess is that one of the dependencies failed to install.
Yes the problem is with rjson which is in prettymapr, which is in turn used by rosm.
Installing package into ‘/home/saquist/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
dependency ‘rjson’ is not available
also installing the dependencies ‘prettymapr’, ‘rosm’
trying URL 'https://cloud.r-project.org/src/contrib/prettymapr_0.2.4.tar.gz'
Content type 'application/x-gzip' length 871428 bytes (851 KB)
==================================================
downloaded 851 KB
trying URL 'https://cloud.r-project.org/src/contrib/rosm_0.2.6.tar.gz'
Content type 'application/x-gzip' length 442336 bytes (431 KB)
==================================================
downloaded 431 KB
trying URL 'https://cloud.r-project.org/src/contrib/ggspatial_1.1.7.tar.gz'
Content type 'application/x-gzip' length 2233717 bytes (2.1 MB)
==================================================
downloaded 2.1 MB
ERROR: dependency ‘rjson’ is not available for package ‘prettymapr’
* removing ‘/home/saquist/R/x86_64-pc-linux-gnu-library/3.6/prettymapr’
Warning in install.packages :
installation of package ‘prettymapr’ had non-zero exit status
ERROR: dependencies ‘rjson’, ‘prettymapr’ are not available for package ‘rosm’
* removing ‘/home/saquist/R/x86_64-pc-linux-gnu-library/3.6/rosm’
Warning in install.packages :
installation of package ‘rosm’ had non-zero exit status
ERROR: dependency ‘rosm’ is not available for package ‘ggspatial’
* removing ‘/home/saquist/R/x86_64-pc-linux-gnu-library/3.6/ggspatial’
Warning in install.packages :
installation of package ‘ggspatial’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpheG11v/downloaded_packages’
> install.packages('prettymapr')
Installing package into ‘/home/saquist/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
dependency ‘rjson’ is not available
trying URL 'https://cloud.r-project.org/src/contrib/prettymapr_0.2.4.tar.gz'
Content type 'application/x-gzip' length 871428 bytes (851 KB)
==================================================
downloaded 851 KB
ERROR: dependency ‘rjson’ is not available for package ‘prettymapr’
* removing ‘/home/saquist/R/x86_64-pc-linux-gnu-library/3.6/prettymapr’
Warning in install.packages :
installation of package ‘prettymapr’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpheG11v/downloaded_packages’
Hmm...it looks like 'rjson' is still on CRAN. Perhaps because it's an old-ish version of R there are no binaries? You may have to try either updating R or installing via RStudio Package Manager, which builds binaries for Windows for older versions of R than version 4.1.
You are right, on the machine I had the error, I have R with version 3.6.3 (2020-02-29), while on my laptop I have R with version 4.2.0 (2022-04-22 ucrt), and that works fine.