library(tidyverse)
library(lubridate)
tibble(
group = c("a", "a", "b", "b"),
dates = ymd(c("2020-01-01", "20220207", "20220209", "20220115"))
) %>%
group_by(group) %>%
summarise(date_range = list(range(dates) %>%
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) | |
c_sort_collapse <- function(...){ | |
c(...) %>% | |
sort() %>% | |
paste(collapse = ".") | |
} | |
unique_combs <- function(...){ | |
list(...) %>% |
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) | |
library(tidymodels) | |
library(workboots) | |
data <- tibble(x = abs(rnorm(1000)), | |
y = x + rnorm(1000, sd = 0.7) * x / (max(x)) | |
) | |
rec <- recipe(y ~ ., data = data) |
library(dplyr)
library(lubridate)
tibble(
file = c("a", "b", "b", "a"),
dates = c("2020-01-01", "01-jan-2020", "15-mar-2020", "2020-03-15")
) %>%
mutate(dates_clean = parse_date_time(dates, orders = c("ymd", "dmy")))
#> # A tibble: 4 x 3
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(rjson) | |
library(httr) | |
library(jsonlite) | |
library(dplyr) | |
library(purrr) | |
library(lubridate) | |
library(rtweet) | |
library(tidyr) | |
get_engagements <- function(user_id, |
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
show_in_excel <- function(.data){ | |
tmp <- paste0(tempfile(), ".csv") | |
write.csv(.data, tmp) | |
fs::file_show(path = tmp) | |
} |
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
# devtools::install_github("brshallo/funspotr") | |
library(funspotr) | |
library(dplyr) | |
# I only kept gists with a .R file extension... | |
# This is a small subset of actual number of R files. | |
github_gists("cmparlettpelleriti") %>% | |
filter(funspotr:::str_detect_r_rmd(contents)) %>% | |
github_spot_funs(custom_urls = .) %>% | |
unnest_github_results() |
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(ggplot2) | |
custom_ggplot <- function(df, x, y, ...){ | |
ggplot(mpg, aes(x = cty, y = hwy, ...))+ | |
geom_point() | |
} | |
custom_ggplot(color = class) | |
p <- custom_ggplot(class = class, displ = displ) |
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) | |
sim_params <- function(n_a = 100, n_b = 400, suffix = ""){ | |
tibble(id = c(rep("a", n_a), rep("b", n_b)), | |
vals = c(rnorm(n_a, 5), rnorm(n_b, 3)) | |
) %>% | |
lm(vals ~ id, data = .) %>% | |
broom::tidy() %>% | |
select(term, estimate) %>% |