Skip to content

Instantly share code, notes, and snippets.

View Aariq's full-sized avatar
🫖

Eric R. Scott Aariq

🫖
View GitHub Profile
library(targets)
tar_dir({
#create 10 identical CSVs as a demo
orig <- tibble::tibble(group = c("A", "A", "A", "B", "B", "C"),
value = 1)
purrr::walk(c(1:10), \(x) write_csv(orig, paste0(x, "-data.csv")))
#_targets.R
tar_script({
library(targets)
gistr
gistr
library(httr2)
# Requests are composable. For example, you could set a bunch of options in a base request used by many other functions
base_req <-
request("https://services.usanpn.org/npn_portal/") |>
req_retry(max_tries = 3, retry_on_failure = TRUE) |> #retry on errors
req_progress(type = "down") |> #display progress bar for large downloads
req_throttle(rate = 30/60) |> #limit request rate to 30 requests per minute
req_user_agent("rnpn (https://github.com/usa-npn/rnpn/)")
library(shiny)
library(tibble)
library(dplyr)
df <- tibble(
ID = 1:5,
age = c("21-30", "21-30", "31-40", "31-40", "70+"),
hispanic_bin = c(1, 0, 1, 0, 1),
white_bin = c(1, 1, 1, 0, 0),
black_bin = c(0, 0, 0, 1, 1)