Skip to content

Instantly share code, notes, and snippets.

View slarge's full-sized avatar

Scott Large slarge

  • NOAA-Fisheries
  • Woods Hole, MA
View GitHub Profile
@slarge
slarge / SpecCode_getDATRAS
Last active February 23, 2016 16:15
Squalus acanthias with getDATRAS()
# Use the devtools package (on CRAN) to get the most up to date version of rICES package (very much in the works) here:
# https://github.com/ices-dk
devtools::install_github("ICES-dk/rICES", force = TRUE)
library(rICES)
# You can get the HL, HH, or CA "EXCHANGE" data using the following function. HH is info on the haul (used to calculate a survey index)
# and HL is the length data. CA is for age info.
# You can make a loop or a function to get data from other surveys. Let it run overnight because there is a lot of data!!!
d <- getDATRAS(record = "HL",
survey="NS-IBTS",
startyear = 2010,
@slarge
slarge / adv-r.md
Created March 1, 2016 14:46 — forked from rmflight/adv-r.md
compiling @hadley books

In the shell:

git clone https://github.com/hadley/adv-r.git
gem install jekyll mime-types

In R:

@slarge
slarge / rollingLM
Created April 20, 2016 11:44
Rolling window linear model
tt <- data.frame(YEAR = seq(1981, 2010, by = 1),
INDICATOR = rnorm(n = 30))
library(zoo)
dolm <- function(x) {
SE <- summary(lm(INDICATOR ~ ., data = as.data.frame(x)))$sigma
SLOPE <- summary(lm(INDICATOR ~ ., data = as.data.frame(x)))$coefficients[1]
return(list(standard.error = SE, slope = SLOPE))
}
rm(list = ls())
# Downloads and parses Calinus finmarchicus abundance data from EMODnet OOPS for the Greater North Sea
# 10 yr rolling mean and 1 yr seasonal data are provided. The latter is probably most relevant for fisheries applications.
# Citation for data: "European Marine Observation Data Network (EMODnet) Biology project (www.emodnet-biology.eu), funded by the European Commission's Directorate - General for Maritime Affairs and Fisheries (DG MARE)"
#
#Install package
install.packages("jsonlite")
library(jsonlite)
#
emodDatJSON <- fromJSON("http://geo.vliz.be/geoserver/Emodnetbio/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Emodnetbio:OOPS_summaries&outputFormat=json")
library(dplyr)
tt <- read.csv("~/AreasEcoregionsStocks.csv",
stringsAsFactors = FALSE)
td <- tt %>%
select(StockCode, Ecoregion1_major, Ecoregion2_minor, Ecoregion3_more_minor) %>%
melt(id.vars = "StockCode") %>%
select(-variable) %>%
filter(value != 0) %>%
distinct()
@slarge
slarge / aggregateICEScatchData.R
Created November 9, 2016 11:03
Takes ICES catch statistics and aggregates according to ICES area and species.
rm(list = ls())
#
library(dplyr, quietly = TRUE)
library(reshape2, quietly = TRUE)
library(ggplot2, quietly = TRUE)
#
options(scipen = 5)
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
# DATA SOURCE: ICES official catch statistics (2006-2014) #
############################
# How many pages of Advice #
############################
##SOURCE
#----pdftools package
#https://cran.rstudio.com/web/packages/pdftools
#INSTALL PACKAGES
#install.packages("pdftools", dependencies=TRUE) #only once
rm(list = ls())
library(data.table)
# Unzip each of the InterCatch download files to a folder "/data" in your working directory
wd <- getwd()
file_list <- paste0(wd,
"/data/",
grep("CatchAndSampleDataTables.txt",
list.files("data/", recursive = TRUE),
@slarge
slarge / navigateSD.R
Created March 7, 2017 13:21
navigate SD
rm(list = ls())
# Load this package, install it if you don't have it already
library(jsonlite)
# Change the active year.
ActiveYear <- 2016
rawsl <- jsonlite::fromJSON(paste0("http://sd.ices.dk/services/odata3/StockListDWs3?$filter=ActiveYear%20eq%20",
ActiveYear),
simplifyDataFrame = TRUE)$value
# colnames(rawsl)
@slarge
slarge / uk_salmon.rmd
Last active March 28, 2017 10:47
Exploration of Bloomberg Politics 3-26-2017 article on how fisheries might be influenced by Brexit
---
title: "UK Salmon"
author: ""
date: "28 March 2017"
output:
pdf_document: default
html_document: default
---
```{r setup, include=FALSE}