_biogeog_workshop_GIS_v3_installation.R
##############################################################
# INTRODUCTORY STUFF
#
# This script is by Nick Matzke (and whoever else adds to this PhyloWiki page)
# Copyright 2011-infinity
# matzkeATberkeley.edu
# January 2011
#
# Please link/cite if you use this, email me if you have 
#   thoughts/improvements/corrections.
#
##############################################################
#
# Free to use/redistribute under:
# Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) 
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the above license, linked here:
# 
# http://creativecommons.org/licenses/by-nc-sa/3.0/
# 
# Summary:
#
# You are free:
#
#   * to Share — to copy, distribute and transmit the work
#   * to Remix — to adapt the work
#
# Under the following conditions:
#
#   * Attribution — You must attribute the work in the manner 
#     specified by the author or licensor (but not in any way that 
#     suggests that they endorse you or your use of the work).
#   * Noncommercial — You may not use this work for commercial purposes. 
#
#   * Share Alike — If you alter, transform, or build upon this work,
#     you may distribute the resulting work only under the same or
#     similar license to this one. 
#
# http://creativecommons.org/licenses/by-nc-sa/3.0/
# 
###################################################################

########################################################
# Script description:
# 
# Help on installing the packages needed for the GIS/phylogenetics
# demo at:
#
# Evolution of Life on Pacific Islands and Reefs: Past, present, and future
# WORKSHOP: Methodological Workshop on Biodiversity Dynamics
# THURSDAY, May 26, 2011: 9am - 1pm
# http://botany.si.edu/events/2011_pacific/program.htm
########################################################

#########################################
# These are the R packages you need to install to run
# The GIS/phylogenetics demo:
# "_biogeog_workshop_GIS_v4.R"
#########################################

# Install packages
install.packages("ape")
install.packages("phylobase")
install.packages("gdata") # needed for trim (whitespace trimming") function
install.packages("lattice") # for histogram

# for mapping
install.packages("maptools")
install.packages("sp")

# for loading ASCII grid
install.packages("adehabitat")
install.packages("maptools")

# For species distribution modelling...
install.packages(c('XML', 'gbm', 'XML', 'deldir', 'gstat', 'randomForest', 'kernlab', 'RgoogleMaps'))

# The package "dismo" I had to install from source (R GUI --> Packages --> Package Manager --> Install From Source)
# But you can try it straight-up also:
install.packages("dismo")

#########################################
# Installing RGDAL
# 
# Notes: RGDAL is an R package that deals with
# geographic projections, rasters/images,
# geographical data formats, etc.
#
# You need it to do the cool geographical
# stuff I did in the demo.
#
# It is basically an R interface to the 
# GDAL library, which uses optimized
# C code to do these operations quickly.
#
# This means you have to:
# 
# 1. Install GDAL on your computer, 
#
# ...THEN AND ONLY THEN...
#
# 2. Install the R package RGDAL in R
# 
# Below are some notes on what worked
# and didn't work, for me, using a Mac OS
# X 10.4.  Your mileage may vary on other
# systems.
#########################################

#########################################
# 1. Trying to install GDAL on the computer
# operating system
#########################################
# The difficulty with manually installing
# GDAL on your system is that the GDAL
# library is dependent on a bunch of
# other libraries.  Installing them all
# can get very frustrating.
#
#######################################
# Best bet on a Mac (worked for me):
# from Terminal: 
# sudo port install gdal
#######################################
#
# Best bet on a PC is to try the GDAL
# binaries (a "binary" or "executable" 
# is a precompiled, ready-to-run / 
# ready-to-execute file)
#
# They are linked from here:
# http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries
#
#######################################

#########################################
# 2. Trying to install RGDAL in R
#########################################

# Attempt #1
# default command - doesn't work
# install.packages("rgdal")     # for readOGR

# Attempt #2
# install.packages(c("rgdal"), lib="/Library/Frameworks/R.framework/Resources/Library/", contriburl=contrib.url(getOption("repos"), type='source', dependencies=TRUE, configure.args=c("--with-proj-lib=/opt/local/lib")     

# Attempt #3
# default with lib flag - also doesn't work
# install.packages(c("rgdal"), lib="/Library/Frameworks/R.framework/Resources/Library/", contriburl=contrib.url(getOption("repos"), type='source'), dependencies=TRUE, configure.args=c("--with-proj-lib=/opt/local/var/macports/software/proj/4.6.1_1/opt/local/lib/") )

# Attempt #4
# Downloaded and manually installed RGDAL; this worked
# You will have to:
#
# 1. Download the rgdal .tar.gz file from here:
# http://cran.r-project.org/web/packages/rgdal/index.html
#
# 2. Set the directories so that R can find:
#  a. your rgdal .tar.gz file
#  b. the directory where the PROJ library has been installed
#     ...you can see below where the "sudo port install gdal"
#     command above installed mine, in a macports subdirectory
# 

install.packages(c("/Users/nick/Desktop/__2011-05-25_Hawaii/downloads/rgdal_0.6-33.tar.gz"), lib="/Library/Frameworks/R.framework/Resources/Library/", NULL, configure.args=c("--with-proj-lib=/opt/local/var/macports/software/proj/4.6.1_1/opt/local/lib/"), type="source")
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License