A translation of the code in this blog post.
View 00_keywords.txt
name keywords | |
Felicitas Development, Corruption, Housing, Transportation, Religion | |
Lucile Inequality, Migration, Race and Gender, Community/Neighborhood | |
Corentin Inequality, Religion, Migration, Poverty, Gender | |
Charlotte Energy, Environment, Smart Cities, Conflict, Gender | |
Alice Environment, Gender, Migration, Urban Studies | |
Miranda Politics, Gender, Human Rights | |
Margaux Inequality, Urban Studies, Migration, Human Rights | |
Marina Critical Theory, Social Inequality, Race and Gender | |
Cosima Race and Gender and Sexuality, Spatial Inequality, Migration |
View pubmed_ask.r
#' Get a PubMed search index | |
#' @param query a PubMed search string | |
#' @return the XML declaration of the search | |
#' @example | |
#' # Which articles discuss the WHO FCTC? | |
#' pubmed_ask("FCTC OR 'Framework Convention on Tobacco Control'") | |
pubmed_ask <- function(query) { | |
# change spaces to + and single-quotes to URL-friendly %22 in query | |
query = gsub("'", "%22", gsub(" ", "+", query)) |
View session_info.r
# ============================================================================== | |
# SESSION_INFO | |
# | |
# A script to deal with package dependencies that will | |
# | |
# - detach all packages except base ones | |
# - install its own package dependencies | |
# - look for session_info.txt and parse it for packages | |
# - ensure the packages are installed and up to date | |
# |
View cleaning_characters.r
# removes characters from multiple data frame columns | |
# example removes * , % characters | |
dw <- data.frame(gsub("\\*|,|%", "", as.matrix(dw)), stringsAsFactors = FALSE) |
View dark_base16-tomorrow-night.rstheme
/* rs-theme-name: Dark UI Base16 Tomorrow Night */ | |
/* rs-theme-is-dark: TRUE */ | |
/* Dark UI from Randy3k's Wombat (https://github.com/randy3k/dotfiles/blob/master/.R/rstudio/themes/Wombat.rstheme) */ | |
/* "Tomorrow night" color scheme adapted from chriskempson's Base16 (https://github.com/chriskempson/base16). */ | |
.body { | |
background: #ffffff; | |
} |
View triangle.py
# triangle.py | |
import math | |
def triangle_perimeter(a, b, c): | |
return a + b + c | |
def triangle_area(a, b, c): | |
p = triangle_perimeter(a, b, c) / 2 | |
x = math.sqrt(p * (p - a) * (p - b) * (p - c)) | |
return round(x, 2) |
View dta_to_sav.r
# package dependency | |
library(haven) | |
path_in = "new_EB with more var_2004-2016.dta" | |
out_tsv = "new_EB.tsv" | |
out_sav = "new_EB.sav" | |
# name repair shows the issue with _merge | |
x = haven::read_dta(p, .name_repair = "universal") | |
names(x)[ names(x) == "._merge" ] = "MERGEVAR" |
View get_points.r
#' Read Points out of a KML file. | |
#' | |
#' @param x A KML file exported from Google Maps. | |
#' @param layer The name of the layer to extract from: defaults to \code{"d1"}. | |
#' @param verbose Whether to report invalid coordinates and/or altitudes below | |
#' sea level; defaults to \code{TRUE}. See \link{kml_coordinate}. | |
#' @return A \link[tibble:tibble]{tibble} containing the \code{name}, | |
#' \code{description}, \code{styleUrl} and Point coordinates (\code{longitude}, | |
#' \code{latitude} and \code{altitude}) of each Placemark element contained in | |
#' the KML file. Placemark elements with no Point coordinates, such as Polygon |
View example.r
x = c("Aaltonen, Markus Sakari", "Stubb, Cai-Göran Alexander", "Ahde, Matti Allan", | |
"Saarakkala, Vesa-Matti", "Aho, Esko Tapani", "Piirainen, Raimo Olavi", | |
"Jääskeläinen, Pietari Osmo", "Juurikkala, Timo Johannes", | |
"Jokinen, Kalle Johannes", "Aho, Raila Orvokki", "Ahonen, Risto Sakari", | |
"Aittoniemi, Sulo Eerikki", "Ahvenjärvi, Sauli Sakari", "Mäkisalo-Ropponen, Merja Elina", | |
"Mäntylä, Hanna Katariina", "Autto, Heikki Samuli", "Ajo, Aimo Olavi", | |
"Mäntymaa, Markku Antero", "Mölsä, Martti Kullervo", "Niikko, Mika Ilari", | |
"Eerola, Juho Seppo Antero", "Eestilä, Markku Yrjö", "Packalén, Tom Erik", | |
"Elomaa, Ritva Tuulikki", "Pekonen, Aino-Kaisa Ilona", "Pelkonen, Jaana Maarit", | |
"Eloranta, Eeva-Johanna", "Donner, Jörn Johan", "Grahn-Laasonen, Sanni Kaisa", |
NewerOlder