Skip to content

Instantly share code, notes, and snippets.

library(data.table)
library(hildaData)
library(hildaExtra)
library(dplyr)
library(dtplyr)
library(magrittr)
get_hilda_xwaveid_age_income <- function(year){
wave <- letters[year - 2000]
if (year == 2014){
library(dplyr)
library(data.table)
library(dtplyr)
library(magrittr)
tbl_sequential <-
CJ(Year = 2011:2014,
Month = 1:12) %>%
mutate(Date = as.Date(paste(Year, Month, "01", sep = "-"))) %>%
write_to_sandbox <- function(filename){
dat <- get(gsub("^.*/([A-Za-z0-9_]+)\\.rda$", "\\1", filename))
fwrite(dat, paste0("~/sandbox/taxstats/", gsub("^.*/([A-Za-z0-9_]+)\\.rda$", "\\1", filename), ".csv"))
}
check_which_nonascii <- function(filename){
tools::showNonASCIIfile(filename)
cat(filename, "\n")
}
@HughParsonage
HughParsonage / investment-property-CGT-25pc-costing.R
Last active February 15, 2017 23:42
Costing of lowering CGT discount to 25 per cent for investment property only
library(taxstats)
library(data.table)
library(grattan)
library(dplyr)
library(dtplyr)
library(magrittr)
sample_file_1314 %>%
project_to(fy.year.of.sample.file = "2013-14", to_fy = "2016-17") %>%
merge(age_range_decoder) %>%
@HughParsonage
HughParsonage / Tax-collected-billions-by-fy-year-and-assumption.R
Created April 28, 2017 08:21
Tax collected over forwards under pessimistic and MYEFO assumptions
library(dplyr)
library(dtplyr)
library(magrittr)
library(data.table)
library(taxstats)
library(grattan)
MYEFO <-
data.table(fy_year = yr2fy(2017:2020),
r = c(0.023, 0.025, 0.033, 0.035))
@HughParsonage
HughParsonage / HILDA-household-stats-for-hhs-retiree-super-exceeds-1,600,000.R
Last active May 9, 2017 11:17
HILDA-household-stats-for-hhs-retiree-super-exceeds-1.6-million
library(testthat)
library(dplyr)
library(dtplyr)
library(data.table)
library(hildaData)
library(hildaExtra)
library(sih.hilda.1314)
library(taxstats)
library(magrittr)
@HughParsonage
HughParsonage / weather_here.R
Created June 25, 2017 01:03
Prints the weather at your location (based on IP)
if (requireNamespace("bomrang", quietly = TRUE)) {
library(data.table)
library(bomrang) # devtools::install_github('ToowoombaTrio/bomrang')
`_nrst_stn_to_me` <- as.numeric(jsonlite::fromJSON("http://ip-api.com/json")[c("lat", "lon")])
weather_here <- function() {
bomrang::get_current_weather(latlon = `_nrst_stn_to_me`, as.data.table = TRUE) %>%
.[, .(local_date_time, weather, rel_hum, apparent_t, air_temp, wind_dir, wind_spd_kt, gust_kt)] %>%
head
}
formalCoverage <- function(fn) {
formalz <<- formals(fn)
bod <<- as.character(body(fn))
formal_present <- function(formal) {
formal_dots_escaped <<- gsub(".", "\\.", formal, fixed = TRUE)
any(grepl(pattern = paste0("(?:\\b|\\s)", formal_dots_escaped, "(?:\\b|\\s)"),
x = bod,
perl = TRUE))
@HughParsonage
HughParsonage / HILDA-household-disp-Gini.R
Created July 25, 2017 14:30
Use HILDA to calculate Gini by household
library(data.table)
library(hildaData)
library(magrittr)
library(grattanCharts)
library(ggplot2)
#' @source acid package (but it's chock full of unnecessary dependencies)
weighted_gini <- function (x, w = NULL) {
if (is.null(w))
w <- rep(1, length(x))
@HughParsonage
HughParsonage / employment-QLD
Last active August 27, 2017 14:05
SA4 employment figures by QLD region
library(grattanCharts) # devtools::install_github('hughparsonage/grattanCharts')
library(dplyr)
library(httr)
library(tidyr)
library(readxl)
library(scales)
library(ggplot2)
library(data.table)
library(lubridate)
library(hutils)