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
export_drive <- function(url, dir = ".", quiet = TRUE, progress = TRUE) { | |
require(googledrive) | |
require(dplyr) | |
require(purrr) | |
if (!dir.exists(dir)) { | |
message("Directory ", dir, " does not exist.") | |
md <- menu(c("Yes", "No (exit)"), title = "Do you want to create it?") | |
if (md == 1L) { | |
dir.create(dir, recursive = TRUE) |
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
v_distance_along <- function(points, line, dist_unit = "km") { | |
# packages | |
require(sf) | |
require(sfnetworks) | |
require(dplyr) | |
require(units) | |
# check inputs | |
if (!inherits(points, "sf") && !inherits(points, "sfc")) { | |
stop("'points' must be an sf or sfc object containing POINT or MULTIPOINT geometries.") | |
} |
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
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 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
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 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
#################################################- | |
## 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 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
#################################################- | |
## 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 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
#################################################- | |
## Subdivide multipolygon by regional multipolygon with sf ---- | |
## W.K. Petry | |
#################################################- | |
## Preliminaries ---- | |
#################################################- | |
library(sf) | |
library(tidyverse) | |
library(cowplot) |
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
# 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 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
#' 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 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
#################################################- | |
## Evaluate color palettes for colorblindness accessibility ---- | |
## W.K. Petry | |
#################################################- | |
## Preliminaries ---- | |
#################################################- | |
library(colorspace) | |
library(colorscience) | |
library(paletteer) # devtools::install_github("EmilHvitfeldt/paletteer") | |
library(tidyverse) |
NewerOlder