Skip to content

Instantly share code, notes, and snippets.

@favstats
favstats / collapseoutput.js
Last active July 13, 2021 09:40 — forked from emitanaka/collapseoutput.js
Collapsible Code Output for `xaringan`
<script>
(function() {
var divHTML = document.querySelectorAll(".details-open");
divHTML.forEach(function (el) {
var preNodes = el.getElementsByTagName("pre");
var outputNode = preNodes[1];
outputNode.outerHTML = "<details open class='output'><summary>Run</summary>" + outputNode.outerHTML + "</details>";
})
})();
(function() {
### The following functions borrow heavily from this gist by @jnolis
### https://gist.github.com/jnolis/a41c196a5e22e2a2115d28e853d4780c
### Unfortunately, the shiny app framework didn't work for me
### So I created an interactive console script that guides you through authentification
### No shiny needed
# This function creates a URL for users to click to authenticate.
# You should use it to show a URL when users haven't authenticated yet.
get_authorization_url <- function(app, permission=NULL){
library(sf)
library(cowplot)
library(showtext)
library(sysfonts)
library(ggplot2)
showtext_auto()
font_add_google("Quicksand")
font_add_google("Fira Sans")
font1 <- "Quicksand"
### Code mostly inspired by https://github.com/HudsonJamie/tidy_tuesday/blob/main/2021/week_46/afrilearndata.R
library(pdftools)
library(tidygeocoder)
library(tidyverse)
library(janitor)
library(rgdal)
library(osmdata)
library(sf)
library(ggfx)
## Create NYT Spiral Animations
## Most Code comes from here: https://bydata.github.io/nyt-corona-spiral-chart/
library(tidyverse)
library(lubridate)
library(gganimate)
library(viridis)
owid_url <- "https://github.com/owid/covid-19-data/blob/master/public/data/owid-covid-data.csv?raw=true"
library(tidyverse)
library(modelbased)
library(magrittr)
overview <- readRDS("data/overview.rds")
## helper function
get_plabs <- function (pval) {
dplyr::case_when(is.na(pval) ~ "", pval < 0.001 ~ "***",
pval < 0.01 ~ "**", pval < 0.05 ~ "*",
library(tidyverse)
library(httr)
token <- Sys.getenv("fb_marketing_token")
#link to fb api
my_lin k<- "https://graph.facebook.com"
#define fields you are interested in
search_fields=c("ad_creation_time",
save_csv <- function(d, path) {
if(file.exists(path)){
readr::write_csv(d, append = T, file = path)
} else {
dirs_to_create <- stringr::str_split(path, "\\/") %>%
unlist() %>%
purrr::discard(~stringr::str_detect(.x, "\\.")) %>%
paste0(collapse = "/")
#===============================================================================
# 2022-07-10
# Year progress twitter
# Fabio Votta (@favstats)
# Idea blatantly stolen from Ilya Kashnitsky (@ikashnitsky)
#===============================================================================
library(tidyverse)
library(magrittr)
library(lubridate)
@favstats
favstats / extract_dat.R
Created July 12, 2022 15:59
Latent GOLD exports data in a very weird way because commas are kept for decimals in a comma-separated data file which leads to issues. This script helps recovering the data by extracting the data row-by-row.
#===============================================================================
# 2022-07-12
# Extract data from Latent GOLD within R
# Fabio Votta (@favstats)
#===============================================================================
library(tidyverse)
library(data.table)
setwd(here::here())