Skip to content

Instantly share code, notes, and snippets.

View jsta's full-sized avatar
🪼
...

Jemma Stachelek jsta

🪼
...
View GitHub Profile
@jsta
jsta / gpkg.md
Last active February 4, 2017 15:45
Setup and test an ubuntu geopackage environment

Setup

docker pull ubuntu

docker run -it ubuntu bash

cat /etc/lsb-release

DISTRIB_ID=Ubuntu

@jsta
jsta / daylength.R
Created February 28, 2017 02:53
Calculate day length
#'@references \url{http://aa.usno.navy.mil/data/docs/RS_OneYear.php}
#'@return A 3 x 365 data.frame of sunrise, sunset, date where times are in GMT
#'@examples \dontrun{
#' sunsetrise_yr(year = 2015, lon_deg = 80, lon_min = 26, lat_deg = 25, lat_min = 5, tz = 5)
#' }
sunsetrise_yr <- function(year, lon_sign = -1, lon_deg, lon_min, lat_sign = 1, lat_deg, lat_min, tz, tz_sign = 1){
url <- "http://aa.usno.navy.mil"
@jsta
jsta / extract_doi.R
Last active March 3, 2017 22:48
Extract doi from bibtex R
dt <- knitcitations::read.bibtex("foo.bib")
dt <- dt[grep("doi", tolower(dt)),]
res <- stringr::str_extract(dt, "(?=10)(.*?)(?<=\\s)")
res <- as.character(sapply(res, function(x) substring(x, 1, nchar(x) - 3)))
(res <- res[!is.na(res)])
# paste0("http://dx.doi.org/", res)
@jsta
jsta / dataone_oneida.R
Last active March 20, 2017 21:24
Automated viz of Oneida Lake benthos data from dataone
library(dataone)
cn <- CNode("PROD")
mn <- getMNode(cn, "urn:node:KNB")
dt <- getPackage(mn, id = "resourceMap_kgordon.4.57")
unzip(dt)
# list.files("resourceMap_kgordon_4_57/data")
dt <- read.csv("resourceMap_kgordon_4_57/data/cbfs.140.3-Oneida_Benthos_1956_to_present.csv",
stringsAsFactors = FALSE)
@jsta
jsta / DESCRIPTION
Last active May 18, 2022 07:36
Import from datasets package
Package: datasets.test
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: c(person("Joseph", "Stachelek", email = "[email protected]", role = c("aut", "cre")))
Description: What the package does (one paragraph).
Depends:
R (>= 3.3.3)
Imports:
datasets
License: GPL (>= 2)
@jsta
jsta / Rprofile.site
Created April 5, 2017 13:55
Rprofile.site
.First <- function() {
options(
repos = c(CRAN = "https://cran.rstudio.com/"),
browserNLdisabled = TRUE,
deparse.max.lines = 2)
}
if (interactive()) {
suppressMessages(require(devtools))
}
@jsta
jsta / upgrade_packages.R
Last active April 26, 2017 16:35 — forked from bearloga/upgrade_packages.R
The script can be used to re-install packages after upgrading R (on Windows), since libraries cannot be reused between different minor versions (e.g. when upgrading 3.2.3 to 3.3.2). It detects when a package was installed from CRAN vs GitHub/Git and re-installs it using the appropriate func. Usage: `Rscript upgrade_packages.R`
#Setup##########################################################################
message("Checking for a personal library...")
if (!dir.exists(Sys.getenv("R_LIBS_USER"))) {
warning("Personal library not found, creating one...")
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)
message("Registering newly created personal library...")
.libPaths(Sys.getenv("R_LIBS_USER"))
} else {
@jsta
jsta / iris_bayesian_lm.R
Created May 1, 2017 00:13
Fit a simple bayesian regression model using the iris dataset
library(rjags)
data(iris)
independent <- iris$Petal.Length
dependent <- matrix(iris$Petal.Width)
lm.m <- lm(independent~dependent)
dependent <- cbind(1, dependent)
@jsta
jsta / iris_naive_bayes.R
Last active May 1, 2017 13:32
Use naive bayes to calculate distribution mean + credible interval
# http://math.utoledo.edu/~mleite/math-EES-seminar/week1Baysean.pdf
data(iris)
# Estimation ####
y <- iris$Sepal.Length
y_bar <- mean(y)
y_sd <- sd(y)
n <- length(y)
@jsta
jsta / KNB.js
Last active May 3, 2017 01:36
KNB Zotero web translator
{
"translatorID": "7a81d945-7d9c-4f8c-bd7b-4226c1cadasd",
"label": "KNB",
"creator": "Joseph Stachelek",
"target": "https://knb.ecoinformatics.org/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,