R Packages

The capabilities of R can be extended through Packages. Here is a little overview of some very useful R packages.

General

# The default path of stored packages is the first of these
.libPaths()
# Install Package
install.packages('maptools')

# Loads package library in R
library(maptools)

 

classInt

Description
Choose univariate class intervals.

Reference manual
http://cran.r-project.org/web/packages/classInt/classInt.pdf

Commands

  • classIntervals
  • findColours

Tutorial
How to use R package ‘classInt’ to choose univariate class intervals

 

Geospatial

rgdal

Description
Provides bindings to Frank Warmerdam’s Geospatial Data Abstraction Library (GDAL).

Dependencies
Depends on R library ‘sp’
‘gdal-config’ has to be installed on the computer:

#!/bin/bash
sudo apt-get install libgdal1-dev
sudo apt-get install libgdal1-dev libproj-dev

Reference manual
http://cran.r-project.org/web/packages/rgdal/rgdal.pdf

Commands

  • SpatialPolygonsDataFrame
  • readOGR
  • writeOGR
    # List all drivers
    .Call("ogr_GetDriverNames", PACKAGE = "rgdal")
    

Tutorial
How to use R-package ‘rgdal’ to read shapefiles

rgeos

Description
Interface to Geometry Engine – Open Source (GEOS) using the C API for topology operations on geometries. For example: simplifying shapefiles.

Reference manual
http://cran.r-project.org/web/packages/rgeos/rgeos.pdf

Command
gSimplify
gIntersection

maptools

Description
Set of tools for manipulating and reading geographic data, in particular ESRI shape-files.

Dependencies
Depends on library ‘sp’

Reference manual
http://cran.r-project.org/web/packages/maptools/maptools.pdf

Commands

  • readShapeLines
  • readShapePoints
  • readShapePoly

Tutorial
How to use R-package ‘maptools’ to read and display shapefiles

maps

Description
Display of maps. Projection code and larger maps are in separate packages:
mapproj and mapdata

Reference manual
http://cran.r-project.org/web/packages/maps/maps.pdf

Commands / Maps
world: from 0 to 360
world2: from -180 to 180

Tutorial
How to read and plot netCDF files with R

ncdf

Description
Interface to Unidata netCDF Data Files

Reference manual
http://cran.r-project.org/web/packages/ncdf/ncdf.pdf

Commands
open.ncdf()
get.var.ncdf()
close.ncdf()

Tutorial
How to read and plot netCDF files with R

Read Excel

gdata

Description
Various R programming tools for data manipulation.

Reference manual
http://cran.r-project.org/web/packages/gdata/gdata.pdf

Command
read.xls

Tutorial
How to read Excel files into R with package ‘gdata’

XLConnect

Description
Manipulate Excel files from R
!!  Only supports format from Excel versions 97/2000/XP/2003 !!
See gdata for newer Excel files!

Error message:
“OldExcelFormatException (Java): The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)”

Dependencies
‘Java Development Kit’ has to be installed on the computer

#!/bin/bash
R CMD javareconf

Reference manual
http://cran.r-project.org/web/packages/XLConnect/XLConnect.pdf

Command
readWorksheetFromFile

Tutorial
How to read Excel files into R with package ‘XLConnect’