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
eval({ | |
ensure_nonnull <- ensures_that(!is.null(.) ~ "Must not be NULL" ) | |
ensure_nonempty <- ensures_that(length(.) > 0 ~ "Must not be empty", +ensure_nonnull ) | |
ensure_finite <- ensures_that(all(is.finite(.)) ~ "Must be finite", +ensure_nonempty ) | |
ensure_positive <- ensures_that(all(. > 0) ~ "Must be positive", +ensure_finite ) | |
ensure_nonnegative <- ensures_that(all(. >= 0) ~ "Must be positive or zero", +ensure_finite ) | |
ensure_unique <- ensures_that(length(unique(.)) == 1) | |
}) | |
# Wrapped in `eval({...})` b/c otherwise RStudio will complain about syntax |
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
# | |
# Context: | |
# | |
# https://cran.r-project.org/web/packages/ensurer/vignettes/ensurer.html says: | |
# "It is also possible to use the dot, ., directly in anonymous error handlers defined directly in the call to e.g. ensure_that." | |
# | |
# I must be misunderstanding the statement above! | |
# | |
library(ensurer) |
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
# $ brew install libssh2 | |
# $ brew install libgit2 | |
## $ export CMAKE_INCLUDE_PATH="/usr/local/Cellar/libssh2/1.7.0/include" | |
## $ export CMAKE_LIBRARY_PATH="/usr/local/Cellar/libssh2/1.7.0/lib" | |
# NOTE: re: git2r: https://github.com/ropensci/git2r/issues/236 | |
install_CRAN <- function (pkg, repos = "http://cran.rstudio.com", verbose = TRUE, ...) { | |
if (pkg %in% installed.packages()) message(pkg, " is already installed") | |
else install.packages(pkg, repos = repos, verbose = verbose, ...) | |
} |
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
grouply <- function(f, ...) { | |
groups <- lazyeval::lazy_dots(...) | |
function(tbl, ...) { | |
dplyr::group_by_(tbl, .dots = groups) %>% | |
f(...) %>% | |
dplyr::ungroup() | |
} | |
} |
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
library(dplyr) | |
library(htmlwidgets) | |
library(rpivotTable) | |
mtcars %>% | |
rpivotTable(rows = "gear", | |
cols = c("cyl", "carb"), | |
vals = "hp", | |
# Step 1. Make this line accomplish the same thing as the default |
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
library(UScensus2010) | |
library(UScensus2010tract) | |
library(UScensus2010blkgrp) | |
library(UScensus2010blk) | |
Cook_tracts <- UScensus2010::county(state = "Illinois", name = "Cook", level = "tract") | |
Cook_tracts@data[1:8, 1:8] | |
plot(Cook_tracts) | |
Cook_blkgrps <- UScensus2010::county(state = "Illinois", name = "Cook", level = "blkgrp") |
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
PY_CCl4_emission_data <- | |
PY(1997:2016) %>% | |
point_source_abated_emissions() %>% | |
filter_pollutants(list(CCl4 = 60)) | |
chart_data <- | |
PY_CCl4_emission_data %>% | |
mutate(fac_h1 = if_else(fac_id == 31, "Dow Chemical", "All Others")) %>% | |
annual_emissions_by(fac_h1) %>% | |
group_by(fac_h1) |
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
# | |
# Turns out that #1350 is the DataBank ID for "Diesel PM". | |
# | |
# Here's an "old-school" way to figure that out. | |
# t0064 contains pollutant metadata. | |
# | |
library(Ingres) | |
help(t0064) # here's some Orange Binder material | |
view(t0064) # type "Diesel" in the search box (upper right) |
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
library(inventory) | |
show138 <- function ( | |
DB_year, | |
category_id, | |
verbose = TRUE | |
) { | |
#' Define the preferred sorting order. | |
PONSCO_vars <- |
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
#' | |
#' Summary Tree Tool | |
#' | |
#' Discover which categories --- or groups of categories --- emit the largest | |
#' share(s) of a particular pollutant. | |
#' | |
#' Version history: | |
#' | |
#' - Created 2015-12-01 by dholstius | |
#' - Last updated 2019-10-23 by dholstius |