This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## custom-color-palettes.r | |
## Defining custom color palettes and loading packages for others | |
## ------------------------------------------------------- | |
## Author: Laura Tremblay-Boyer ([email protected]) | |
## Written on: August 20, 2015 | |
## Time-stamp: <2015-08-20 10:12:30 lauratb> | |
require(RColorBrewer) | |
require(colorspace) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# table2pdf() | |
# Creates pdf table from matrix or dataframe | |
# Author: Laura Tremblay-Boyer, UBC Fisheries Centre | |
# Contact: [email protected] | |
# Note 1: Current version works on Mac, but can be tweaked for a PC. | |
# You need a working version of latex in your computer. Make sure | |
# latex in your R search path. Sys.getenv("PATH") will show you the value | |
# of your current path, see ?Sys.getenv and Details section in ?latex for more. | |
if(!grepl("tex",Sys.getenv("PATH"))) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## add-continents.r | |
## Defines function add.continents() which adds a quick, low-level | |
## outline of the world's continents to an existing plot | |
## (i.e. no need to fuss around with special map classes, | |
## but the resulting outline is coarse) | |
## if use.ndc = TRUE, will draw continents over the entire figure | |
## device | |
## ------------------------------------------------------- | |
## Author: Laura Tremblay-Boyer ([email protected]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.First.sys() # loads all base packages, etc. before doing .Rprofile commands | |
# packages to load | |
#library(data.table) | |
# set locale to utf-8 | |
#Sys.setlocale("LC_ALL", "en_US.UTF-8") | |
Sys.setlocale("LC_ALL", "fr_FR.UTF-8") | |
message("Locale set to UTF-8 (or not, check in Rprofile)\n -- won't work for PF project, required for GS Soproner") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Define load path | |
(add-to-list 'load-path "~/.emacs.d/") | |
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/") | |
;;; Set preferred encoding to utf-8 | |
;;; when using shell within emacs (M-x shell) | |
(set-terminal-coding-system 'utf-8) | |
(set-keyboard-coding-system 'utf-8) | |
(prefer-coding-system 'utf-8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check.dev.size <- function(ww,hh) { | |
if(dev.cur()==1){ dev.new(width=ww,height=hh) | |
} else { | |
ds <- dev.size() | |
if(round(ds[1],2)!=round(ww,2) | |
| round(ds[2],2)!=round(hh,2)) { | |
dev.off(); dev.new(width=ww,height=hh)} } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getmatch <<- function(x,str2match,...) { | |
unlist(regmatches(x,regexpr(str2match,x,...))) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## file-scan.r | |
## Function to find a pattern in files with user-defined extension (.r by default) | |
## Returns file name and approximate row matches if positive. | |
## ------------------------------------------------------- | |
## Author: Laura Tremblay-Boyer ([email protected]) | |
## Written on: March 26, 2013 | |
## Time-stamp: <2013-03-26 16:19:28 Laura> | |
file.scan <- function(pattern, dir=getwd(), fpattern=NA, ftype=".r") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Function to extract GODAS oceanography data | |
#from SPC databases (adapted from Simon Hoyle) | |
#Gets the value from the nearest lon/lat grid cell | |
#lat resolution is 1/3 of a degree, lon is 1 degree | |
#Started: <2013-03-14 15:29:57 Laura> | |
#Time-stamp: <2013-03-15 14:37:55 Laura> | |
getGODAS <- function(tb,variable,year,month,rlat,rlon) { |