Skip to content

Instantly share code, notes, and snippets.

View adamhsparks's full-sized avatar
🇦🇺

Adam H. Sparks adamhsparks

🇦🇺
View GitHub Profile
@adamhsparks
adamhsparks / bomrang_climogram.R
Last active July 3, 2019 04:32
Generate a climogram using bomrang to download station data for 2018/19 summer growing season in Australia
library(bomrang)
library(tidyverse)
library(theme.usq)
# Find stations ----------------------------------------------------------------
# Find nearest stations for each area
# search https://www.latlong.net/ for the lat lon values of each location
# clermont
# see https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
# core
brew install coreutils
# key commands
brew install binutils
brew install diffutils
brew install ed
brew install findutils
@adamhsparks
adamhsparks / bibtex_2academic.R
Created February 14, 2019 10:45 — forked from lbusett/bibtex_2academic.R
script for importing publications from a "bibtex" file to a hugo-academic website
#' @title bibtex_2academic
#' @description import publications from a bibtex file to a hugo-academic website
#' @author Lorenzo Busetto, phD (2017) <lbusett@gmail.com>
bibtex_2academic <- function(bibfile,
outfold,
abstract = FALSE,
overwrite = FALSE) {
require(RefManageR)
@adamhsparks
adamhsparks / _Nvim-R-Tmux.md
Created January 9, 2019 01:52 — forked from tgirke/_Nvim-R-Tmux.md
Nvim-R-Tmux: An Integrated Working Environment for R
@adamhsparks
adamhsparks / save_all_on_error.R
Created August 24, 2018 22:53
Save all output from long running R operation in .rda file
save_all <- function() {
save.image("recover.rda")
}
options(error = save_all)
@adamhsparks
adamhsparks / geom_point_sf.md
Created August 20, 2018 20:16 — forked from andrewheiss/geom_point_sf.md
geom_point and geom_sf
library(tidyverse)
library(sf)

Generate fake data (tribble() is a cool function, btw)

events <- tribble(
  ~event, ~latitude, ~longitude,
@adamhsparks
adamhsparks / add_p_r2_eqn.R
Last active May 17, 2019 16:47
Add p-value, R2 and equation to linear models in ggplot2
library(ggplot2)
df <- data.frame(x = c(1:100))
df$y <- 2 + 3 * df$x + rnorm(100, sd = 40)
m <- lm(y ~ x, data = df)
summary(m)
# see that p <2e-16
# function to create the text equation
@adamhsparks
adamhsparks / microbenchmark_code.R
Created November 7, 2017 04:16
Skeleton for microbenchmarking R code and graphing it
library(microbenchmark)
mbm <- microbenchmark(
one = function(),
two = function(),
times = 50
)
mbm
library(ggplot2)
autoplot(mbm)
@adamhsparks
adamhsparks / ftp_file_list.R
Last active May 10, 2024 11:04
list ftp site files using {curl} (not {RCurl}) in R
ftp_base <- "ftp://"
list_files <- curl::new_handle()
curl::handle_setopt(list_files, ftp_use_epsv = TRUE, dirlistonly = TRUE)
con <- curl::curl(url = ftp_base, "r", handle = list_files)
files <- readLines(con)
close(con)
lib <- .libPaths()[1]
pkgs <- as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package
install.packages(pkgs, type = "source")