Skip to content

Instantly share code, notes, and snippets.

Avatar

Davis Vaughan DavisVaughan

View GitHub Profile
View slide-date-lookback.R
library(slider)
library(dplyr)
library(lubridate)
df <- tibble(
x = c(.5, .8, .7, .5, .2, .06, 0, 0, 0, 0, 0, .1, .3, .2, 0),
date = as.Date("2005-07-20") + 0:14
)
# Check that the window made up of "the current day plus 4 days before it" are all >0
View flexible-joins.R
library(dplyr)
x <- tibble(
a1 = c(1, 5, 7, 12),
a2 = c(4, 6, 11, 15)
)
y <- tibble(
b = c(2, 3, 1, 4, 6, 0, 14)
)
View clock-almanac-shifting.R
library(clock)
library(almanac)
library(tidyr)
# All possible Monday/Friday pairs in 2019
# (note some will be invalid, which will need to be removed)
grid <- expand_grid(
year = 2019,
month = 1:12,
day = c(clock_weekdays$monday, clock_weekdays$friday),
View recipe-grow.r
library(recipes)
library(butcher)
library(rlang)
my_function2 <- function() {
a <- iris
b <- iris
c <- iris
rec <-
View lubridate-posixct-wildness.R
x <- lubridate::today()
x
#> [1] "2021-04-12"
# not what i wanted...
# (treats the Date as UTC, then shows it to you in your local tz)
as.POSIXct(x)
#> [1] "2021-04-11 20:00:00 EDT"
# probably what you wanted:
View lubridate-between.R
library(dplyr)
library(lubridate)
set.seed(123)
today <- as.Date("2021-04-12")
df <- tibble(x = today + sample(-(1:100), size = 50))
df %>%
mutate(
res_between = case_when(
View memtools-windows.r
> devtools::load_all()
Loading memtools
Re-compiling memtools
- installing *source* package 'memtools' ... (719ms)
** using staged installation
** libs
"C:/rtools40/mingw64/bin/"gcc -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I./rlang -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c arrow.c -o arrow.o
"C:/rtools40/mingw64/bin/"gcc -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I./rlang -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c dominance.c -o dominance.o
"C:/rtools40/mingw64/bin/"gcc -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I./rlang -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c globals.c -o globals.o
"C:/rtools40/mingw64/bin/"gcc -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I./rlang -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c init.c -o init.o