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
# Load necessary library | |
pacman::p_load( | |
stringi, data.table, duckplyr, readr, dplyr, collapse, duckdb, dbplyr, bench, | |
ggplot2 | |
) | |
# Function to generate a dataframe chunk | |
generate_data_chunk <- function(num_rows = 1000, num_cols = 100) { | |
# Generate numeric columns | |
numeric_cols <- replicate(n = num_cols/2, expr = runif(num_rows, 1, 10000), simplify = FALSE) |
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
# Load necessary library | |
pacman::p_load( | |
stringi, data.table, duckplyr, readr, dplyr, collapse, duckdb, dbplyr, bench, | |
ggplot2 | |
) | |
# Function to generate a dataframe chunk | |
generate_data_chunk <- function(num_rows = 1000, num_cols = 100) { | |
# Generate numeric columns | |
numeric_cols <- replicate(n = num_cols/2, expr = runif(num_rows, 1, 10000), simplify = FALSE) |
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
#' Fix broken Census Connecticut blocks post-2022 | |
#' See: https://github.com/walkerke/tigris/issues/178 | |
library(tigris) | |
library(sf) | |
library(dplyr) | |
library(readr) | |
library(testthat) | |
# load official CT crosswalk | |
# missing a few block ids, but tracts are a consistent 1:1 merge so use those |
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
# quick R script for seeing the trends in downloads for a package | |
library(cranlogs) | |
library(ggplot2) | |
library(collapse) | |
library(lubridate) | |
package <- "shiny" | |
# get downloads for a specific date | |
x <- cran_downloads(packages=shiny, from="2015-06-01", to="2023-08-14") | |
head(x) |
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
# list and unlist an sf object | |
library(collapse) | |
library(sf) | |
library(testthat) | |
nc <- st_read(system.file("shape/nc.shp", package="sf")) | |
nc_list <- rsplit(nc, by = seq_len(nrow(nc))) | |
nc_collapse <- unlist2d(nc_list, idcols = FALSE, recursive = FALSE) |> |
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 all indexes, then drop and add before and after writing to table | |
# Speeds up writes | |
get_index_table <- function(con, tablename, schemaname) { | |
index_df <- dbGetQuery(con, paste0( | |
"SELECT indexname, indexdef FROM pg_indexes | |
WHERE tablename = '", tablename, "' AND schemaname = '", schemaname, "'")) | |
index_df <- subset(index_df, !grepl("[pf]key", indexname)) | |
index_df$indexname <- paste0(schemaname, ".", index_df$indexname) |
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
if(!require(pacman)) install.packages('pacman') | |
pacman::p_load(tigris, tidycensus, furrr, purrr, tictoc, ggplot2) | |
options(tigris_use_cache = FALSE) # make things equal between runs | |
state_names <- c(state.name, "District of Columbia") | |
names(state_names) <- state_names | |
# purrr: | |
tictoc::tic() |
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
# Create census commute share in Portland | |
if(!require(pacman)) install.packages('pacman') | |
pacman::p_load(dplyr, tidycensus) | |
# https://data.census.gov/cedsci/table?q=means%20transportation&g=1600000US4159000&tid=ACSDT1Y2021.B08006 | |
trans_table <- 'B08006' | |
# note, no data for 2020, the 2005 data is corrupt : | |
# the non-auto counts are off | |
years <- c(2006:2019, 2021) |
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
license: mit |
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
license: mit |
NewerOlder