Skip to content

Instantly share code, notes, and snippets.

@mbacou
mbacou / snippets.R
Last active May 2, 2024 22:34
How to read and write STATA variable and value labels from R.
# Using read.dta() to load a sample STATA data file
dta <- read.dta("my_toy_data.dta")
# Let's describe dta
str(dta)
#'data.frame': 95202 obs. of 13 variables:
# $ hh : num 1.01e+09 1.01e+09 1.01e+09 1.01e+09 1.01e+09 ...
#$ h14aq2 : Factor w/ 61 levels "matooke","matooke",..: 50 51 34 47 57 41 22 1 13 53 ...
#$ h14aq3 : Factor w/ 93 levels "Kilogram (kg)",..: 51 26 85 1 NA 1 55 70 1 33 ...
#$ h14aq4 : num 0.5 4 4 1 NA 1.5 5 3 4 10 ...
@mbacou
mbacou / userChrome.css
Last active March 23, 2024 01:19
Thunderbird chrome (Ubuntu 16.10)
@namespace url ("http: //www.mozilla.org /keymaster/gatekeeper/there.is.only.xul");
#msgHeaderView {
border-bottom: 0 !important;
}
#folderPaneBox {
padding-top: 1em;
border: 0 !important;
}
@mbacou
mbacou / emacs.el
Created March 6, 2017 10:12
Emacs init file (Ubuntu 16.10)
;; Load themes
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(blink-cursor-mode nil)
'(c-ignore-auto-fill (quote (cpp)))
@mbacou
mbacou / snippets.R
Last active March 20, 2022 23:46
Working with attributes inside SpatialPolygonsDataFrame objects
## Example procedure for working with data (attributes) inside SpatialPolygonsDataFrame objects
# Load my favorite libraries for that sort of work
library(data.table)
library(rgdal)
# Load 2 shapefiles that, say, we want to merge.
# Note that you can read pretty much any spatial format using readOGR().
tza.l2 <- readOGR("./analysis/TZA-AC-07/maps", "tza-ac-07_L2")
tza.l1 <- readOGR("./analysis/TZA-AC-07/maps", "tza-ac-07_L1")
@mbacou
mbacou / opencpu_nproc_error.R
Last active August 8, 2020 22:37
Repex for OpenCPU failed child process error
#' Repex - download 1200+ raster layers from USGS
#' @import data.table stringr
#' @importFrom tools file_path_sans_ext
#' @export
step1 = function(
x = c("2001-01-01", "2004-12-31"),
dir = tempdir()
) {
if(!dir.exists(dir)) dir.create(dir)

Keybase proof

I hereby claim:

  • I am mbacou on github.
  • I am mbacou (https://keybase.io/mbacou) on keybase.
  • I have a public key whose fingerprint is EA64 AE9F 84B8 42EE 2D21 73BE F19A 4463 D73C E3FE

To claim this, I am signing this object:

@mbacou
mbacou / mbacou-theme.el
Created August 17, 2017 00:43
theme for emacs-nox
(deftheme mbacou
"Created 2013-03-25.")
(custom-theme-set-variables
'mbacou
'(ansi-term-color-vector [unspecified "#555555" "#a40000" "#61862F" "#c4a000" "#204a87" "#7653C1" "#4C8FC7" "#ECECEC"]))
(custom-theme-set-faces
'mbacou
'(show-paren-match ((t (:background "#eeeeee"))))
@mbacou
mbacou / emacs-nox.el
Created August 17, 2017 00:40
Standard emacs configuration on Ubuntu 16.04 cloud server
;; Load themes
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector
[default bold shadow italic underline bold bold-italic bold])
@mbacou
mbacou / snippets.R
Last active June 12, 2017 22:16
Spatial operations: dissolve and overlay
setwd("/home/projects")
library(data.table)
library(rgdal)
library(rgeos)
library(maptools)
library(stringr)
# Load GAUL 2008 (release 2009) adm-2 from Darby
g <- readOGR("./maps/admin", "g2008_2")
@mbacou
mbacou / gnome-shell.css
Created March 6, 2017 10:18
Flat-Plat-compact (customized GTK3 and gnome-shell theme)
/* This stylesheet is generated, DO NOT EDIT */
/* Copyright 2009, 2015 Red Hat, Inc.
*
* Portions adapted from Mx's data/style/default.css
* Copyright 2009 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
*