Skip to content

Instantly share code, notes, and snippets.

View Andrei-WongE's full-sized avatar
💭
I may be slow to respond.

Andrei-WongE Andrei-WongE

💭
I may be slow to respond.
View GitHub Profile
@MilesMcBain
MilesMcBain / lon_lat_to_point.R
Last active April 30, 2020 00:54
lon_lat_to_point
##' Create an sf POINT column from long and lat columns
##'
##' This is a vectorised function that takes 2 columns of longitude and latitude
##' as arguments and returns a simple features geometry collection column in the
##' EPSG 4326 coordinate reference system (lon, lat).
##'
##' @title lon_lat_to_point
##' @param lon a numeric column of longitudes
##' @param lat a numeric column of latitudes
##' @return a simple features collection column of POINT geometries representing the lon/lat pairs.
@dantonnoriega
dantonnoriega / cool-bash-code.sh
Last active April 21, 2024 20:00
a collection of cool bash scripts
# cool bash codes
# search a directory for all lines that match a pattern (not perfect but useful) ------
## e.g. grep is searching for all lines matching "::" in `R/` to determine package calls
## -h hides the file names; -i ignores case
## sed -E uses regular expressions to search and match groups;
## we then sort and use -u
grep -hi :: -R R/* | sed -E 's/(.*)([ ]+[a-z]+::)(.*)/\2/g' | sort -u
# COUNT COLUMNS -----------------
@ikashnitsky
ikashnitsky / explain-map-borders.R
Last active January 1, 2023 17:33
Give an example how and why to use line borders instead of polygons outlines in maps -- https://ikashnitsky.github.io/2023/map-borders
#===============================================================================
# 2020-04-08 -- twitter upd 2023-01-01 ik-q
# Showcase the map hack -- use border lines instead of polygon outlines
# https://twitter.com/ikashnitsky/status/1247875600305598464
# https://ikashnitsky.github.io/2023/map-borders
# Ilya Kashnitsky, [email protected]
#===============================================================================
library(tidyverse)
library(sf)
@mikedecr
mikedecr / smartly-reinstall-R-pkgs.R
Last active November 30, 2021 20:42
When you're installing packages after a major R upgrade and you DON'T just want to get everything from CRAN.
# ----------------------------------------------------
# Installing packages for new R version.
# Michael DeCrescenzo
#
# Hi, I'm a political science PhD student looking for
# a data science/quantitative research/statistics job.
# Learn more at <mikedecr.github.io> and <github.com/mikedecr>
#
# This script deals with the following problem:
# I upgraded to new major version of R, & I want to reinstall packages.
@jlacko
jlacko / rstudio-init-script.R
Last active July 7, 2021 21:35
Init script for new RStudio installation, promoting best practices
# make certain jsonlite is available
if(!require(jsonlite, quietly = TRUE)) {
install.packages("jsonlite")
library(jsonlite)
}
# get the path to settings file
path <- if (Sys.info()[["sysname"]] == "Windows") {
paste0(Sys.getenv('APPDATA'), "\\RStudio\\rstudio-prefs.json")
} else {
@richarddmorey
richarddmorey / planning_precision.Rmd
Created June 12, 2020 16:30
Figures for "Power and precision" blog post
---
title: "Power and precision"
author: "Richard D. Morey"
date: "11/06/2020"
output:
html_document:
dev: png
self_contained: no
editor_options:
chunk_output_type: console
library(tidyverse)
library(brms)
library(Amelia)
library(broom)

set.seed(1234)
data("africa")

# Impute missing data with Amelia (since it handles country/year panel stuff really well)
@obrl-soil
obrl-soil / tilt_stack_sf.R
Last active December 7, 2023 15:29
Tilted and stacked maps with sf
# further to https://urbandemographics.blogspot.com/2016/04/creating-tilted-and-stacked-maps-in-r.html,
# an sf-friendly approach.
library(sf)
nc <- st_read(system.file('shape/nc.shp', package = 'sf'))
plot(nc)
sm <- matrix(c(2, 1.2, 0, 1), 2, 2)
#!/bin/bash
funzip $1| # uncompress first file in zip
tr -d '\000' | #remove null characters
sed "/^\s*$/d; s/ \{1,\}\t/\t/g; s/\t \{1,\}/\t/g; s/\r//" | #removes empty lines, whitespace around tabs, extra newlines
cut -s -f 1,3,4,5,6,8,12,13,14,15,16,17,18,19,20,21,23,24,25,26,34,35,36,38,40,42,44,45,46,85,86,87,88,89 #| #only select certain columns
pv -N Process -c |
gzip -9 |
pv -N Compress -c > $1.gz
@saveyak
saveyak / arts_education_NOLA.R
Created February 25, 2021 16:41
Arts Education in New Orleans
#I wrote this code to produce the graphics used in the public policy report, "Will the Arts Come Marching In? Access to Arts Education in Post-Katrina New Orleans," by Sarah Woodward of Tulane University. Read the report here: https://educationresearchalliancenola.org/files/publications/20200915-Woodward-Will-the-Arts-Come-Marching-in-Access-to-Arts-Education-in-Post-Katrina-New-Orleans.pdf
library(readxl)
library(tidyverse)
library(ggplot2)
library(extrafont)
library(scales)
library(grid)
library(stringr) #lets you use str_wrap()