Skip to content

Instantly share code, notes, and snippets.

Andy Teucher ateucher

Block or report user

Report or block ateucher

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View rle_eg.md
values <- runif(100)

# get runs where values > 0.75 (these are TRUE/FALSE)
runs <- rle(values > 0.75)

# Mask out the runs with lengths < 3
runs$values[runs$lengths < 3] <- FALSE

# Get a vector of positions that meet the run criteria
View RStudio_bcmaps_unititled_0C2B9F8D
values <- runif(100)
# get runs where values > 0.75 (these are TRUE/FALSE)
runs <- rle(values > 0.75)
# Mask out the runs with lengths < 3
runs$values[runs$lengths < 3] <- FALSE
# Get a vector of positions that meet the run criteria
masked <- inverse.rle(runs)
View bcdata_fwa_example.md
# remotes::install_github("bcgov/bcdata", ref = "promise")
library(bcdata)
library(ggplot2)

Use bcdc_get_data() to get an entire dataset. I wouldn't recommend this for really large datasets like the FWA:

View habc_api.md
library(rgdal)
#> Loading required package: sp
#> rgdal: version: 1.4-3, (SVN revision 828)
#>  Geospatial Data Abstraction Library extensions to R successfully loaded
#>  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
#>  Path to GDAL shared files: /Users/ateucher/Rlibrary/rgdal/gdal
#>  GDAL binary built with GEOS: FALSE 
#>  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
#>  Path to PROJ.4 shared files: /Users/ateucher/Rlibrary/rgdal/proj
View RStudio_air-zone-reports_assign_time.R
library(dplyr)
library(lubridate)
# sample table
foo <- tibble(
a = rnorm(5),
date = seq(Sys.Date(), by = "1 day", length.out = 5),
he = 1:5
)
View bc_wms_tiles.R
library(bcmaps)
library(leaflet)
library(sf)
st_transform(bc_bound(), 4326) %>%
leaflet() %>%
#add basemap
#addpolygons and make it show in three different layers, by risk level
addPolygons() %>%
addProviderTiles(providers$CartoDB.DarkMatter,
View cake.R
library(datasauRus)
library(ggplot2)
library(ggrepel)
library(viridisLite)
is_equal <- function(x, y, ...) {
vapply(x, function(i) identical(all.equal(i, y, ...), TRUE), FUN.VALUE = logical(1))
}
up <- 12
View pa_analysis_with_dl.sql
-- Before running, load ecoregions, ecosections, bec, nr regions
-- to the db with the same schema.table name as in bcgw
-- This assumes using ogr2ogr for the load, it creates the objectid columns
-- ----------------------------
-- first, overlay designatedlands with nr regions
-- ----------------------------
DROP TABLE IF EXISTS nr_sub;
CREATE TABLE nr_sub AS
@ateucher
ateucher / rasterizing
Created Sep 26, 2018 — forked from boshek/rasterizing
Comapring POSTGIS rasterization with fasterize
View rasterizing
library(sf)
library(dplyr)
library(fasterize)
shape <- "MULTIPOLYGON (((1126095 1246073, 1126221 1246053, 1126358 1246059, 1126383 1245909, 1126457 1245800, 1126605 1245831, 1126756 1245812, 1126812 1245652, 1126805 1245526, 1126841 1245377, 1126859 1245227, 1126868 1245077, 1126881 1244927, 1126949 1244805, 1126954 1244667, 1126806 1244635, 1126658 1244602, 1126508 1244591, 1126358 1244591, 1126283 1244701, 1126248 1244825, 1126256 1244951, 1126219 1245100, 1126197 1245249, 1126175 1245374, 1126145 1245498, 1126114 1245622, 1126025 1245743, 1125919 1245839, 1125803 1245897, 1125638 1245928, 1125547 1246037, 1125693 1246143, 1125842 1246150, 1126095 1246073)))"
tictoc::tic()
## Actually connect to the database
@ateucher
ateucher / mgcv-posterior-animate.R
Created Sep 5, 2018 — forked from noamross/mgcv-posterior-animate.R
Animating smoothing uncertainty in a GAM
View mgcv-posterior-animate.R
library(tidyverse)
library(gganimate)
library(mgcv)
library(mvtnorm)
# Fit a GAM to the data
mod <- gam(hp ~ s(mpg), data=mtcars, method="REML")
# Get the linear prediction matrix
newdat = data.frame(
You can’t perform that action at this time.