This file contains 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
get_bb_snow <- function(){ | |
require(rvest) | |
require(tidyverse) | |
require(janitor) | |
require(lubridate) | |
snow <- rvest::read_html("https://www.gothicwx.org/long-term-snow.html") %>% | |
rvest::html_element(".tableizer-table") %>% | |
rvest::html_table(header = TRUE, na.strings = c("NA", "")) %>% | |
janitor::row_to_names(1) %>% |
This file contains 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
library(tidyverse) | |
library(lme4) | |
library(gamm4) | |
# simulate data | |
set.seed(238472) | |
simdat <- tibble(env = c(seq(0, 1, length.out = 20), | |
seq(2, 3, length.out = 20), | |
seq(4, 5, length.out = 20)), | |
site = rep(letters[1:3], each = 20), |
This file contains 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
#################################################- | |
## Download search results from a Web of Science web query ---- | |
## W.K. Petry | |
## | |
## example usage: | |
## get_wos_query(url = "https://www.webofscience.com/wos/woscc/summary/83c53a2b-5a39-4468-84f0-c9ffcfba5e91-01b947ba/relevance/1", profile = fprof) | |
#################################################- | |
## Define function to fetch WoS query hits ---- | |
#################################################- | |
get_wos_query <- function(url, browser = c("firefox", "chrome", "phantomjs"), |
This file contains 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
#################################################- | |
## Functions to check status of git repos in a given folder ---- | |
## W.K. Petry | |
## | |
## inspired by @djnavarro's workbch::view_git_status | |
#################################################- | |
## Helper fxn to fail gracefully for local-only repos ---- | |
## with no upstream | |
#################################################- | |
ab_poss <- purrr::possibly(.f = ~as.data.frame(as.list(git2r::ahead_behind(local = .x, upstream = .y)), |
This file contains 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
#################################################- | |
## Subdivide multipolygon by regional multipolygon with sf ---- | |
## W.K. Petry | |
#################################################- | |
## Preliminaries ---- | |
#################################################- | |
library(sf) | |
library(tidyverse) | |
library(cowplot) |
This file contains 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
# WindRose.R | |
# modified from https://stackoverflow.com/questions/17266780/wind-rose-with-ggplot-r | |
require(ggplot2) | |
require(RColorBrewer) | |
require(dplyr) | |
require(tidyr) | |
plot.windrose <- function(data, | |
spd, | |
dir, |
This file contains 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
#' Retrieve attached or loaded package names and their version numbers | |
#' | |
#' @param L an object of class 'sessionInfo'. Default is to retrieve the current | |
#' workspace session information. | |
#' @param n character specifying whether to use attached packages ('otherPkgs') or | |
#' packages only loaded via a namespace ('loadedOnly'). Base packages are always | |
#' omitted. | |
#' | |
#' @return a data frame with two columns: the package name and the package version number. | |
#' @export |
This file contains 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
#################################################- | |
## Evaluate color palettes for colorblindness accessibility ---- | |
## W.K. Petry | |
#################################################- | |
## Preliminaries ---- | |
#################################################- | |
library(colorspace) | |
library(colorscience) | |
library(paletteer) # devtools::install_github("EmilHvitfeldt/paletteer") | |
library(tidyverse) |
This file contains 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
## Generate random compositions that sum to <=1 | |
library(gtools) | |
library(ggtern) | |
library(scatterplot3d) | |
rCompos <- function(n, subsamples, alphas = NULL){ | |
if(is.null(alphas)) alphas <- rep(1, subsamples) | |
sums <- matrix(runif(n), ncol = 1) | |
dirichlet <- gtools::rdirichlet(n, alphas) |
This file contains 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
# somewhat hackish solution to: | |
# https://twitter.com/EamonCaddigan/status/646759751242620928 | |
# based mostly on copy/pasting from ggplot2 geom_violin source: | |
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r | |
library(ggplot2) | |
library(dplyr) | |
"%||%" <- function(a, b) { |
NewerOlder