Skip to content

Instantly share code, notes, and snippets.

View aammd's full-sized avatar

Andrew MacDonald aammd

  • Université de Sherbrooke
  • Montreal, Canada
View GitHub Profile
@aammd
aammd / mkrproj.sh
Created January 3, 2018 14:59 — forked from bearloga/mkrproj.sh
A bash shell script that can be used to turn the current directory into an RStudio project, opening the project in RStudio after creating it.
#!/bin/bash
# Usage: mkproj [projectname]
# projectname defaults to name of current directory
template="Version: 1.0\nRestoreWorkspace: Default\nSaveWorkspace: Default\nAlwaysSaveHistory: Default\n\nEnableCodeIndexing: Yes\nUseSpacesForTab: Yes\nNumSpacesForTab: 4\nEncoding: UTF-8\n\nRnwWeave: knitr\nLaTeX: pdfLaTeX"
wd=$(basename `pwd`)
if [ -z $1 ]; then
## Empty list -- just use the empty environment for this.
nil <- function() {
emptyenv()
}
## Test if a list is the empty list:
is_empty <- function(lis) {
identical(lis, nil())
}
@aammd
aammd / boot.R
Created June 12, 2014 21:08 — forked from davharris/boot.R
set.seed(1)
# Create fake data
x = runif(100, 0, 5)
y = .25 * x^3 - x^2 + rnorm(length(x))
data = data.frame(x = x, y = y)
# Identify 500 points to include in the plots
x.sequence = seq(0, 5, length = 500)
getmatch <<- function(x,str2match,...) {
unlist(regmatches(x,regexpr(str2match,x,...))) }
@aammd
aammd / refexp.r
Created July 24, 2013 18:14 — forked from emhart/refexp.r
library(lme4)
library(ggplot2)
#create some levels
levs <- as.factor(c("l1","l2","l3","l4","l5"))
#set the factor means
f_means <- c(6,16,2,10,13)
# set individual as a factor
## 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 (l.boyer@fisheries.ubc.ca)
## Written on: March 26, 2013
## Time-stamp: <2013-03-26 16:19:28 Laura>
file.scan <- function(pattern, dir=getwd(), fpattern=NA, ftype=".r") {
@aammd
aammd / ch2.R
Created November 5, 2012 22:58 — forked from mabarbour/ch2
Code for recreating figures in Chapter 2
######### These are my attempts to incorporate McCann's models into R to help me interpret these food web models ######################
library(deSolve)
### Section 2.2.5
# parameters and state variables for the R-M model
r <- 1.0 # per capita rate of increase in resource
K <- 2.0
e <- 0.7
Ro <- 0.5