Reputation: 13
I'm attempting to install the raster package to be able to run a model in RStudio - I'm using Ubuntu 20.04, and R 4.2.1. Whenever I run install.packages('raster')
in the RStudio console I get this error. I've already installed r-cran-raster for Ubuntu, am using a PPA, and have tried downloading the raster package to manually install.
I am relatively new to R and Ubuntu, so would appreciate any suggestions for what to try!
error message from install.packages('raster')
:
** R
** inst
** byte-compile and prepare package for lazy loading
in method for ‘brick’ with signature ‘x="kasc"’: no definition for class “kasc”
in method for ‘brick’ with signature ‘x="grf"’: no definition for class “grf”
in method for ‘coerce’ with signature ‘"STFDF","RasterBrick"’: no definition for class “STFDF”
in method for ‘coerce’ with signature ‘"STSDF","RasterBrick"’: no definition for class “STSDF”
in method for ‘coerce’ with signature ‘"asc","RasterLayer"’: no definition for class “asc”
in method for ‘coerce’ with signature ‘"RasterLayer","asc"’: no definition for class “asc”
in method for ‘coerce’ with signature ‘"kasc","RasterBrick"’: no definition for class “kasc”
in method for ‘coerce’ with signature ‘"kasc","RasterStack"’: no definition for class “kasc”
in method for ‘coerce’ with signature ‘"kde","RasterLayer"’: no definition for class “kde”
in method for ‘coerce’ with signature ‘"grf","RasterBrick"’: no definition for class “grf”
in method for ‘coerce’ with signature ‘"grf","RasterLayer"’: no definition for class “grf”
in method for ‘extent’ with signature ‘x="bbox"’: no definition for class “bbox”
in method for ‘extent’ with signature ‘x="sf"’: no definition for class “sf”
in method for ‘extract’ with signature ‘x="Raster",y="sf"’: no definition for class “sf”
in method for ‘mask’ with signature ‘x="Raster",mask="sf"’: no definition for class “sf”
in method for ‘raster’ with signature ‘x="sf"’: no definition for class “sf”
in method for ‘raster’ with signature ‘x="kasc"’: no definition for class “kasc”
in method for ‘raster’ with signature ‘x="asc"’: no definition for class “asc”
in method for ‘raster’ with signature ‘x="kde"’: no definition for class “kde”
in method for ‘raster’ with signature ‘x="grf"’: no definition for class “grf”
in method for ‘rasterize’ with signature ‘x="sf",y="Raster"’: no definition for class “sf”
Creating a generic function for ‘rowSums’ from package ‘base’ in package ‘raster’
Creating a generic function for ‘colSums’ from package ‘base’ in package ‘raster’
in method for ‘setValues’ with signature ‘x="RasterLayerSparse"’: no definition for class “RasterLayerSparse”
in method for ‘stack’ with signature ‘x="kasc"’: no definition for class “kasc”
munmap_chunk(): invalid pointer
Aborted (core dumped)
ERROR: lazy loading failed for package ‘raster’
* removing ‘/home/emmsage/R/x86_64-pc-linux-gnu-library/4.2/raster’
Warning in install.packages :
installation of package ‘raster’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpuqJnA5/downloaded_packages’
Upvotes: 1
Views: 1399
Reputation: 368409
The answer by @Zheyuan is very good and complete and detailed, and utilises the existing Ubuntu binaries -- and appropriate PPAs -- well.
But more recently, a new choice became available via the r2u setup I created. It is very similar, but offers all of CRAN as binaries for Ubuntu 20.04 and 22.04. Myself and a few other already use it quite extensively.
I recorded a quick animated gif to show it which I will post at Twitter in a reference to this answer (I cannot post gifs over 2mb here, hence the detour). I use Docker here to simulate an "empty" system with R and not much else under 20.04 "focal". The r2u has the setup steps you would need to make in a simple script you can exmine and carefully run its five steps.
Once done, you get install.packages("raster")
to give you all the binaries in one step. (In the video I also tell my computer the local address of the server. That is only needed here and not generally.)
Upvotes: 1
Reputation: 73385
Package raster depends on terra, which has system requirement on external libraries.
On Ubuntu 20.04, do the following.
Install GEOS
# Add the Ubuntu GIS PPA
sudo add-apt-repository ppa:ubuntugis/ppa
## update cache
sudo apt-get update
# Install the packages
sudo apt-get install software-properties-common geos
Install GDAL
sudo apt-get install libpq-dev gdal-bin libgdal-dev
Install PROJ
sudo apt-get install proj-bin
Install sqlite3
sudo apt install sqlite3
Only after these, can you do install.packages("raster")
in R.
Upvotes: 0