Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rgdal package installation

Tags:

r

maps

The issue here is not exactly how to plot maps through R, as I have found already a pretty nice example here, but rather how to make it work. In fact, I am unable to load library rgdal:

library(rgdal) Error in library(rgdal) : there is no package called ‘rgdal’ 

However, when I try to install the above package manually, I get the following error:

.... configure: error: proj_api.h not found in standard or given locations. ERROR: configuration failed for package ‘rgdal’ * removing ‘/home/eualin/R/i686-pc-linux-gnu-library/2.15/rgdal’ Warning in install.packages : installation of package ‘/home/eualin/Downloads/rgdal_0.8-5.tar.gz’ had non-zero exit status 

Any input welcome!

like image 940
user706838 Avatar asked Mar 06 '13 13:03

user706838


People also ask

How do you install package in R?

Open R via your preferred method (icon on desktop, Start Menu, dock, etc.) Click “Packages” in the top menu then click “Install package(s)”. Choose a mirror that is closest to your geographical location. Now you get to choose which packages you want to install.

How do I install multiple R packages at once?

You can install multiple packages by passing a vector of package names to the function, for example, install. packages(c("dplyr", "stringr")) . That function will install the requested packages, along with any of their non-optional dependencies.


2 Answers

I f you look at the package page on CRAN, you will see the following :

SystemRequirements: for building from source: GDAL >= 1.7.1 library from http://trac.osgeo.org/gdal/wiki/DownloadSource and PROJ.4 (proj >= 4.4.9) from http://trac.osgeo.org/proj/; GDAL OSX frameworks built by William Kyngesburye at http://www.kyngchaos.com/ may be used for source installs on OSX.

As you seem to be under Linux, you always build package from source, so you will have to install the corresponding libraries on your system. If you are under Mint, Ubuntu or another Debian derivative, you can do :

$ sudo apt-get install libgdal1-dev libproj-dev 

One tip that can be useful, still under a Debian based system, is to install the apt-file package and run :

$ sudo apt-file update 

Then, when you get an error such as :

configure: error: proj_api.h not found in standard or given locations. 

You can use the following command to find which package you must install to get the missing file :

$ apt-file search proj_api.h libproj-dev: /usr/include/proj_api.h 
like image 85
juba Avatar answered Sep 27 '22 21:09

juba


If you use OS X with the Homebrew package manager, and have R installed through the homebrew-science tap, you can install rgdal by first installing gdal.

brew install gdal 

You may first want to list the options available before you run this in case you want something fancy like postgresql support. To see the available options type

brew options gdal 

then to be fancy you can type

brew install --with-postgresql gdal 

after a while you should be good to go with dependencies, since proj including your needed proj_api.h are dependencies! Unfortunately, rgdal still won't find pro_api.h right now since it isn't looking in /usr/local/include. To fix this and other possible maladies with your rgdal installation, use the following R command to install rgdal:

  > install.packages('rgdal', type = "source", configure.args=c('--with-proj-include=/usr/local/include','--with-proj-lib=/usr/local/lib')) 

This should be similar to what you would also need for MacPorts with the exception of the brew steps, and your libraries/headers are most likely under "/opt/local/lib" and "/opt/local/include" respectively.

Note: to brew upgraders if you are using "--with-armadillo" as an option with gdal, and upgraded armadillo to 7 from 6. You will have to recompile gdal before you upgrade/reinstall rgdal.

like image 25
Jonathan Lisic Avatar answered Sep 27 '22 20:09

Jonathan Lisic