Skip to content

Instantly share code, notes, and snippets.

@HughParsonage
HughParsonage / snow.R
Created December 26, 2023 05:17
Snow?
snow <- function() {
w <- getOption("width")
flakes <- c(rep(" ", 10), "*", " ", " ", "*", "❄︎", "❅", "❆")
falls <-
vapply(1:50, function(x) {
paste0(sample(flakes, size = w - 10, replace = TRUE), collapse = "")
}, FUN.VALUE = "")
panes <- lapply(1:50, function(x) {
#' @return Character vector of postcodes on 2016 basis
latlon2poa <- function(lat, lon, shapefile.dir = Sys.getenv("POA_2016_SHAPEFILE_DIR")) {
stopifnot(!anyNA(lat), !anyNA(lon), is.numeric(lat), is.numeric(lon),
# Basic check for lat=lon mixup
max(lat) <= 90)
if (!dir.exists(shapefile.dir)) {
tempf <- tempfile()
dir.create(tempf)
exts <- c("dbf", "prj", "shp", "shx", "xml")
# Base URL
@HughParsonage
HughParsonage / Rprofile-site.R
Created April 21, 2019 05:51
My Rprofile.site
# Things you might want to change
# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")
# set the default help type
# options(help_type="text")
options(help_type="html")
options(askYesNo = function(msg, default = NA, prompts, ...) {
@HughParsonage
HughParsonage / avgTax-vs-Age-1516-rel-0304
Last active November 5, 2018 05:13
Average income tax by age 2015-15 vs 2003-04 (in 2015-16 dollars)
library(data.table)
library(grattan)
library(hutils)
library(magrittr)
library(ggplot2)
RQ("grattanCharts",
devtools::install_github("hughparsonage/grattanCharts"))
library(grattanCharts) # hughparsonage/grattanCharts
@HughParsonage
HughParsonage / HESSIH201516-12.R
Last active September 18, 2018 01:18
Proportion of asset value vs net worth decile by age by asset type
stopifnot(file.exists("12.R"),
basename(dirname(normalizePath(dir(pattern = "^12.R$",
full.names = TRUE),
winslash = "/"))) == "issues")
library(data.table)
library(magrittr)
library(hutils)
library(grattan)
@HughParsonage
HughParsonage / test-revdep-datatable.R
Created April 22, 2018 12:00
Test post devtools::revdep()
# bad_names <- names(checksMini)
bad_names <- c("AF", "AFM", "aLFQ", "annovarR", "antaresProcessing", "BatchExperiments",
"BatchJobs", "BGData", "biomartr", "brainGraph", "bupaR", "BuyseTest",
"Causata", "cdparcoord", "cffdrs", "classifierplots", "clickstream",
"corpustools", "corregp", "ctmm", "cvAUC", "dartR", "dat", "dataPreparation",
"DCD", "dfmeta", "dgo", "DGVM3D", "Diderot", "difconet", "drgee",
"dynamichazard", "easycsv", "eclust", "edgeRun", "EdSurvey",
"eeptools", "eiCompare", "EthSEQ", "EurosarcBayes", "EventStudy",
"expss", "fdq", "FedData", "Fgmutils", "flippant", "fst", "genBart",
"GenomicTools", "GGIR", "ggswissmaps", "greport", "hisse", "Hmisc",
"windows" : {
"script_commands": [
"\"C:/R/R-3.4.3/bin/x64/Rscript.exe\" -e \"knitr::knit('$file_name')\"",
// "texify --pdf $file_base_name.tex",
"pdflatex -interaction=batchmode",
"biber $file_base_name",
"pdflatex -interaction=batchmode",
"pdflatex -interaction=batchmode"
]
// See README or third-party documentation
@HughParsonage
HughParsonage / stata_summary.R
Last active February 21, 2018 14:00 — forked from leeper/stata_summary.R
Stata-style regression summaries
stata_summary <-
function(
x,
...
) {
# summarize
mod <- x
x <- summary(x)
# find outcome variable
@HughParsonage
HughParsonage / price2income-vs-housingper1000-by-Country.R
Last active February 19, 2018 11:57
Price 2 income vs Housing per capita (The Satisfaction of Cowgill)
library(rsdmx)
library(data.table)
library(hutils)
library(magrittr)
library(ggplot2)
library(ggrepel)
ISO3166 <- Census2016.spec:::ISO3166 # hughparsonage/Census2016.spec
to_name <- function(a3) {
ISO3166[["name"]][match(a3, ISO3166[["alpha_3"]])]
library(data.table)
library(magrittr)
library(grattan)
library(SampleFile1415)
library(taxstats)
library(hutils)
library(scales)
tax2014 <- copy(sample_file_1415) %>% apply_super_caps_and_div293()