Skip to content

Instantly share code, notes, and snippets.

# Get Country 3 letters ISO code and correct the ones not mapping to FIFA data
iso_url <- "https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3"
iso_html <- xml2::read_html(iso_url)
iso_country <- iso_html %>%
rvest::html_table(fill=TRUE) %>%
.[2:4] %>%
dplyr::bind_rows() %>%
purrr::set_names(c("code","country")) %>%
dplyr::mutate(country=if_else(country=="Côte d'Ivoire",
"Ivory Coast", country),
europe <- c("France", "United Kingdom", "Belgium", "Italy", "Spain",
"Luxembourg", "Ireland", "Netherlands", "Portugal", "Andorra",
"Denmark", "Sweden", "Finland","Germany", "Poland", "Greece",
"Macedonia", "Bosnia-Herzegovina", "Serbia", "Croatia", "Bulgaria",
"Romania", "Hungary", "Czech Republic", "Lithuania", "Estonia",
"Austria", "Slovakia", "Slovenia", "Albania", "Latvia", "Moldova",
"Switzerland", "Belarus")
readr::read_csv("~/Desktop/week13_alcohol_global.csv") %>%
dplyr::select(-total_litres_of_pure_alcohol, -spirit_servings) %>%
@xvrdm
xvrdm / useR2018.md
Created July 11, 2018 13:31 — forked from HanjoStudy/useR2018.md
useR2018 Material

I am looking forward to meeting you at the Tuesday AM (10th of July) tutorial session at useR2018!. We will be discussing a subject that I am very passionate about: Web Scraping!

The slides can be found here:

To ensure that we can be immediately productive on Tuesday morning, I would like you to get the following set up on your machines beforehand:

library(tidycensus)
library(mapdeck)
library(tidyverse)
token <- "your mapbox token"
hv <- get_acs(geography = "tract",
variables = "B25077_001",
state = "CA",
geometry = TRUE) %>%
##################################################################
## Function ##
##################################################################
fish <- function(l, keys, .dflt = NULL, missing.rm = FALSE) {
if(!is.list(keys)) stop("The keys to search should be given as a list.")
modified_names <- names(keys) %||% rep("", length(keys)) %>%
str_replace("^$", as.character(NA))
@xvrdm
xvrdm / table.md
Last active January 28, 2019 10:10
Comparaison Table: fs / base / shell

dir_

fs base shell
dir_ls("/path") list.files("/path") ls /path
dir_info("/path") do.call(rbind, lapply(list.files("/path"), file.info)) ls -al /path
dir_copy("/path", "/new-path") dir.create("/new-path"); file.copy("/path", "/new-path", recursive=TRUE) cp /path /new-path
dir_create("/path") dir.create("/path") mkdir /path
dir_delete("/path") unlink("/path", recursive = TRUE) rm -rf /path
dir_exists("/path") dir.exists("/path") if [ -d "/path" ]; then ... ; fi
@xvrdm
xvrdm / gist:72e7eb17fa0f351a1d7550663f8bf713
Created February 7, 2019 13:51
Gruvbox Colorscheme for Kitty Terminal
#: Color scheme {{{
foreground #ebdbb2
background #282828
#: black
color0 #282828
color8 #928374
#: red
tribble(
~Shoe, ~Max_Size, ~Min_Size,
"sneakers", 34, 28,
"leather", 39, 30)
@xvrdm
xvrdm / between_caveat
Created December 2, 2020 09:52
{dplyr}'s between cannot take multiple values vectors for left/right boundaries
> between(c(5,6), left = c(1,4), right = c(2,10))
[1] FALSE FALSE
> tibble(val = c(5,6), min_threshold = c(1,4), max_threshold = c(2,10)) %>%
mutate(is_in_range = between(val, min_threshold, max_threshold))
# A tibble: 2 x 4
val min_threshold max_threshold is_in_range
<dbl> <dbl> <dbl> <lgl>
1 5 1 2 FALSE
@xvrdm
xvrdm / machine.js
Created December 15, 2020 13:57
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions