Skip to content

Instantly share code, notes, and snippets.


François Briatte briatte

View GitHub Profile
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
briatte / pubmed_ask.r
Last active Oct 19, 2020
pubmed scraper
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
# ==============================================================================
# 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
briatte / cleaning_characters.r
Last active Aug 12, 2020
a few lines of code to load packages, download and scrape data, convert, sort, etc.
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 ( */
/* "Tomorrow night" color scheme adapted from chriskempson's Base16 ( */
.body {
background: #ffffff;
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)
briatte /
Last active Mar 29, 2020
from networkx (Python) to igraph (R)
View dta_to_sav.r
# package dependency
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"
briatte / get_points.r
Last active Jan 8, 2020
R: Create tibbles from Points and Polygons in a Google Maps KML file – not particularly efficient code, but should do the trick; answer to
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",
You can’t perform that action at this time.