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(tidyverse) | |
# grid_ym ---- | |
.years <- 2017:2018 | |
.months <- 1:12 | |
grid_ym <- | |
crossing( | |
year = .years, | |
month = .months |
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
dir_pkgs_rds <- 'c:/users/aelhabr/desktop' | |
r_version_prev <- '3.5' | |
r_version_new <- '4.0' | |
path_rds_prev <- file.path(dir_pkgs_rds, sprintf('pkgs_%s.rds', r_version_prev)) | |
dir_pkgs_installed <- 'c:/users/aelhabr/documents/r/win-library' | |
# ---- | |
# + Open RStudio. | |
# + Run the top-level lines. |
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
.verbose <- TRUE | |
.display_info <- function(x, ..., .envir = parent.frame(), verbose = .verbose) { | |
if(!verbose) { | |
return(invisible(NULL)) | |
} | |
# usethis::ui_line(glue::glue('{x}'), .envir = .envir) | |
# Reference: `usethis::ui_line()` | |
x <- glue::glue_collapse(x, '\n') | |
x <- glue::glue(x, .envir = .envir) |
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
# NOTE: Most of these are from my {vp2} project, which builds upon other past work. | |
file_path <- function(...) { | |
file.path(..., fsep = '/') | |
} | |
# Reference: https://github.com/tonyelhabr/nba-rapm/blob/master/R/files.R | |
.create_dir_ifnecessary <- | |
function(dir, ...) { | |
if(!dir.exists(dir)) { |
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
# NOTE: Most of these are from my {vp2} project, which builds upon other past work. | |
.validate_path <- function(x, strict = TRUE, verbose = TRUE) { | |
# stopifnot(length(x) == 1, is.character(x)) | |
file_exists <- file.exists(x) | |
if(strict) { | |
stopifnot(file_exists) | |
return(invisible(TRUE)) | |
} else { | |
if(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
download_spdf_bound_ercot <- function(..., path = config$path_spdf_bound, backup = FALSE) { | |
url <- 'http://www.ercot.com/content/cdr/static/ercot_boundary.kml' | |
download.file(url = url, destfile = config$path_kml_bound, quiet = TRUE) | |
bound <- | |
config$path_kml_bound %>% | |
xml2::read_xml() %>% | |
xml2::xml_children() %>% | |
xml2::xml_children() %>% | |
magrittr::extract(4) %>% |
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
import_andor_export <- | |
function(..., | |
data = NULL, | |
f = NULL, | |
.otherwise = NULL, | |
file = NULL, | |
ext = '.RData', | |
dir = 'output', | |
path = NULL, | |
var = NULL, |
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_config_schedule <- | |
function(path = NULL, | |
..., | |
dir = getwd(), | |
file = NULL, | |
index = 1, | |
taskname = NULL, | |
validate = FALSE) { | |
if(is.null(path)) { | |
path <- file.path(dir, file) |
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(magrittr) | |
start <- Sys.time() | |
end <- Sys.time() | |
dur <- (end - start) %>% lubridate::as.duration() | |
dur_s <- round(as.numeric(dur, 'seconds'), 1) %>% scales::comma() | |
dur_m <- round(as.numeric(dur, 'minutes'), 1) %>% scales::comma() | |
cat(glue::glue('action took {dur_s} seconds ({dur_m} minutes) to complete.')) |
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(tidyverse) | |
# general helper function | |
retrieve_sb_events <- | |
function(competition_id, | |
..., | |
clean = TRUE, | |
export = TRUE, | |
dir = 'data', | |
ext = 'rds', |
OlderNewer