Skip to content

Instantly share code, notes, and snippets.

View alex-gable's full-sized avatar

Alex Gable alex-gable

View GitHub Profile
@alex-gable
alex-gable / yoy-plot.R
Last active December 23, 2021 01:15
year over year for daily time series with ggplot (hack)
library(tidyverse)
library(lubridate)
# also uses quantmod, zoo, sfthemes, janitor
# less noisy
options("getSymbols.warning4.0" = FALSE)
# example daily time series for multiple years
goog_price <- quantmod::getSymbols(Symbols = "GOOG",
auto.assign = FALSE) %>%
@alex-gable
alex-gable / update_pak.R
Last active September 8, 2021 07:09
update function that works with pak
update_pak <- function() {
`%>%` <- magrittr::`%>%`
pl <- pak::lib_status() %>%
dplyr::mutate(package_full =
dplyr::case_when(
dplyr::coalesce(repository, remotetype) == "CRAN" ~ package,
dplyr::coalesce(repository, remotetype) == "github" ~
paste0(remoteusername, "/", remoterepo),
TRUE ~ NA_character_)) %>%
@alex-gable
alex-gable / initialize-r-project-main.R
Last active June 3, 2021 14:44
R project Init with usethis + renv
#' initialize_project
#'
#' @param database_user defaulted to `NULL`. if you use a database in your
#' project, this parameter takes your username as its value
#' prompts for creation if not
#' @param use_renv should the project use renv?
#' @param use_vscode do you use vscode for your project?
#' @param include_readme creates a README.md file
#' @param include_sql creates a directory for sql files
#' @param include_data creates a directory for data in, out, and temporary
@alex-gable
alex-gable / lubridate-example.R
Created April 6, 2019 18:33
date differences using lubridate
library(lubridate)
bday <- lubridate::as_date("2000-09-15")
today <- lubridate::as_date("2018-09-15")
tomorrow <- lubridate::as_date("2018-09-16")
bday%--%today / lubridate::years(1)
# [1] 18
as.numeric(as.duration(bday%--%today)) / (60*60*24*365.25)