Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Finishing up 2020

Nicholas Tierney njtierney

:octocat:
Finishing up 2020
View GitHub Profile
View understanding-buffer.md
source("https://gist.githubusercontent.com/njtierney/3d8f6b3714860fb2a91fd2c5700e3d53/raw/14226d5d78609e99896450fbd07d82c60875b6cb/oz-map-states.R")
source("https://gist.githubusercontent.com/njtierney/fa383d40c4923a25d39684788dfb6c0e/raw/f80e018a1675da5ac663bb5c5615c80c4cecc41e/aawt-tracks.R")
source("https://gist.githubusercontent.com/njtierney/781bffd9f86509e180d8c86f8289ba20/raw/7ad2b929c9f0001dc45b9e112ad57db41a0a372d/bom-stations-sf.R")

library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
library(dplyr)
#> 
#> Attaching package: 'dplyr'
View bom-stations-sf.R
bom_stations_sf <- structure(list(site = c("001006", "001007", "001018", "001019",
"001020", "001025", "001036", "002012", "002032", "002056", "002064",
"002079", "003003", "003030", "003032", "003057", "003080", "003093",
"003102", "003108", "004019", "004028", "004032", "004083", "004090",
"004095", "004100", "004106", "005007", "005008", "005017", "005084",
"005094", "005098", "006011", "006022", "006044", "006072", "006092",
"006099", "006105", "006108", "007045", "007139", "007176", "007185",
"007600", "008025", "008095", "008137", "008138", "008251", "008290",
"008296", "008297", "008315", "009021", "009037", "009053", "009091",
"009106", "009111", "009114", "009131", "009172", "009178", "009193",
View aawt-tracks.R
aawt_tracks <- structure(list(name = c("Day 01 Walhalla-O'Sheas Track", "Day 02 O'Sheas - St Gwinear Track",
"Day 03 St Gwinear - Stronachs Track", "Day 04 Stronachs - Red Jacket Track",
"Day 05 Red Jacket - Black River Track", "Day 06 Black R - Mt Skene Track",
"Day 07 Mt Skene - Low Saddle Track", "Day 08 Low Saddle - E Barly Rd Track",
"Day 09 E Barkly Rd - Chester Yd Track", "Day 10 Chester Yd - Vallejo Gantner H Track",
"Day 11 Vallejo Gantner H - Catherine Saddle Track", "Day 12 Catherine Saddle - Barry Saddle Track",
"Day 13 Barry Saddle - S Selwyn Track", "Day 14 S Selwyn - Murrays H site Track",
"Day 15 Murrays H Site - Diamontina H Track", "Day 16 Diamontina H - Cope H Track",
"Day 17 Cope H - Ropers H Track", "Day 18 Ropers H - Cleve Cole H Track",
"Day 19 Cleve Cole H - Mt Willis H Track", "Day 20 Mt Willis H - Horsefield C Track",
View oz-map-states.R
oz_map_aawt_states <- structure(list(featurecla = c("Admin-1 scale rank", "Admin-1 scale rank",
"Admin-1 scale rank"), scalerank = c(2L, 2L, 2L), adm1_code = c("AUS-2654",
"AUS-2656", "AUS-2653"), diss_me = c(2654L, 2656L, 2653L), iso_3166_2 = c("AU-NSW",
"AU-VIC", "AU-ACT"), wikipedia = c(NA_character_, NA_character_,
NA_character_), iso_a2 = c("AU", "AU", "AU"), adm0_sr = c(1L,
5L, 1L), name = c("New South Wales", "Victoria", "Australian Capital Territory"
), name_alt = c(NA_character_, NA_character_, NA_character_),
name_local = c(NA_character_, NA_character_, NA_character_
), type = c("State", "State", "Territory"), type_en = c("State",
"State", "Territory"), code_local = c(NA_character_, NA_character_,
View map-centroid-issue.md
options(tidyverse.quiet = TRUE)
library(tidyverse)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1

gist_url <- "https://gist.githubusercontent.com/njtierney/0d61ff809f2c8b72ae70204dfce740cf/raw/ffef6895973203e6b8a125aac4d9d175508cea0c/example-route.R"

source(gist_url)

aawt_dat_1_5 %>% 
View example-route.R
aawt_dat_1_5 <- structure(list(name = c("Day 01 Walhalla-O'Sheas Track", "Day 02 O'Sheas - St Gwinear Track",
"Day 03 St Gwinear - Stronachs Track", "Day 04 Stronachs - Red Jacket Track",
"Day 05 Red Jacket - Black River Track"), geometry = structure(list(
structure(list(structure(c(146.448553959, 146.447833031,
146.448767027, 146.449276982, 146.449859021, 146.449353006,
146.449780986, 146.450464027, 146.451027961, 146.450072005,
146.449651988, 146.44959298, 146.449441016, 146.449607983,
146.449026028, 146.448741965, 146.448881021, 146.449406985,
146.449002977, 146.44853401, 146.447276976, 146.446752017,
146.445404962, 146.444614967, 146.443750961, 146.442599036,
View predicted-values.md
library(tidyverse)
df <- tibble(category = c("A", "B")) %>% 
  group_by(category) %>% 
  mutate(values = map(100, rnorm)) %>% 
  unnest_longer(col = values)  %>% 
  group_by(category) %>% 
  mutate(pred = mean(values))

df %>% 
View exploring-duplicates.md
library(tidyverse)
library(glue)
#> 
#> Attaching package: 'glue'
#> The following object is masked from 'package:dplyr':
#> 
#>     collapse

dupe_df <- function(.data){
View rename-file-helpers.R
rename_with_dash <- function(dir){
files_to_rename <- list.files(dir,
pattern = "_",
recursive = TRUE,
full.names = TRUE)
files_new_names <- files_to_rename %>%
str_replace_all(pattern = "_", replacement = "-")
walk2(files_to_rename,
View example-leaflet.R
library(leaflet)
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
add_birthplace_marker <- function(map, popup = "The birthplace of R"){
map %>%
addMarkers(lng=174.768, lat=-36.852, popup= popup)
}