Skip to content

Instantly share code, notes, and snippets.

Avatar

Bryan Shalloway brshallo

View GitHub Profile
@brshallo
brshallo / convert-currencies.R
Last active Aug 5, 2022
Improved and functionalized version of code pulled mostly from post on pricing -- can see this gist sourced in Appendix of post: https://www.bryanshalloway.com/2022/06/16/converting-between-currencies-using-pricer/#
View convert-currencies.R
library(priceR)
library(dplyr)
library(tidyr)
library(purrr)
library(lubridate)
# Create rates lookup table
pminmax <- function(x, y) {
paste(pmin.int(x, y), pmax.int(x, y), sep = ".")
View unique-set-speed-test.R
library(dplyr)
c_sort_collapse <- function(...){
c(...) |>
sort() |>
paste(collapse = ".")
}
unique_set <- function(...){
list(...) |>
View unique-combinations.R
library(dplyr)
c_sort_collapse <- function(...){
c(...) %>%
sort() %>%
paste(collapse = ".")
}
unique_combs <- function(...){
list(...) %>%
View check-workboots-heteroskedasticity.R
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)
View range-to-min-max.md
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) %&gt;% 
View different-date-formats.md
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")))
#&gt; # A tibble: 4 x 3
@brshallo
brshallo / get-engagements.R
Last active Apr 17, 2022
Function to get all various types of engagements from Twitter for a user
View get-engagements.R
library(rjson)
library(httr)
library(jsonlite)
library(dplyr)
library(purrr)
library(lubridate)
library(rtweet)
library(tidyr)
get_engagements <- function(user_id,
View show_in_excel.R
show_in_excel <- function(.data){
tmp <- paste0(tempfile(), ".csv")
write.csv(.data, tmp)
fs::file_show(path = tmp)
}
View funspotr-gists-cmparlettpelleriti-ex.R
# 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()
@brshallo
brshallo / custom-ggplot-and-labels.R
Last active Dec 22, 2021
Nice way to pass in arbitrary labels to plotly::ggplotly()
View custom-ggplot-and-labels.R
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)