Skip to content

Instantly share code, notes, and snippets.

@long39ng
long39ng / postgres-unnest-json.R
Last active November 18, 2022 11:35
Unnest fields from a JSON/JSONB column to new columns in a PostgreSQL database table
#' Unnest fields from a JSON/JSONB column in a PostgreSQL database table
#'
#' @inheritParams dbplyr:::select.tbl_lazy
#' @param .json_col Unquoted name of the JSONB column
#' @param ... Expressions in the syntax `<new_column_name> = "<json_field_name>"`
#'
unnest_json <- function(.data, .json_col, ...) {
.json_col <- rlang::ensym(.json_col)
col_names <- rlang::enexprs(...)
library(httr2)
corona_platform_api <- function(endpoint, ...) {
request("https://www.corona-datenplattform.de/api/3/action") |>
req_url_path_append(endpoint) |>
req_url_query(...) |>
req_perform() |>
resp_body_json()
}
# https://jokergoo.github.io/2020/06/08/multiple-group-chord-diagram/
library(circlize)
library(tidyverse)
choices <- tribble(
~A, ~B, ~C, ~D, ~E, ~F,
NA, 2, NA, 3, 1, NA,
NA, 1, 3, NA, NA, 2,
NA, 1, 2, NA, NA, 3,
NA, 2, NA, 3, 1, NA,
library(tidyverse)
library(osmdata)
library(sf)
# Define functions --------------------------------------------------------
query_streets <- function(place) {
query <- getbb(place) |>
opq()
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(tidyverse)
library(sf)
@long39ng
long39ng / ridge_lat.R
Last active September 16, 2021 15:04
library(tidyverse)
library(sf)
library(stars)
# Migrazensus dataset downloaded from: https://doi.org/10.7910/DVN/GPEV4P
migrazensus <- read_csv(here::here("migrazensus_v0.2.csv")) |>
mutate(wknr_2021 = as.double(wknr_2021))
# Shape files downloaded from
# https://www.bundeswahlleiter.de/dam/jcr/67e3e9b8-dbca-4bc9-8977-ac792665bbce/btw17_geometrie_wahlkreise_vg250_shp.zip
library(RSelenium)
selenium_driver <- rsDriver(browser = "firefox")
selenium_driver$client$navigate("https://impffrei.work/wp-sitemap-posts-job_listing-1.xml") # :facepalm:
Sys.sleep(12)
page_source <- selenium_driver$client$getPageSource()
@long39ng
long39ng / theme_538_mono_demo.R
Last active February 8, 2021 22:17
Fivethirtyeight ggplot2 theme by Dr. Thomas Mock with monospaced axis text
library(tidyverse)
library(ggtext)
library(espnscrapeR)
# Custom theme function ----
theme_538 <- function(..., base_size = 12) {
theme(
# plotting components
@long39ng
long39ng / springer_dl.R
Created April 27, 2020 10:25
Script to download all Springer books released for free during the 2020 COVID-19 pandemic
library(tidyverse)
library(httr)
library(fs)
library(here)
titles_url <- "https://resource-cms.springernature.com/springer-cms/rest/v1/content/17858272/data/v4"
dl_folder <- "downloads"
# Save Excel table to tmp folder