This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| stata_summary <- | |
| function( | |
| x, | |
| ... | |
| ) { | |
| # summarize | |
| mod <- x | |
| x <- summary(x) | |
| # find outcome variable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"]])] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(magrittr) | |
| library(grattan) | |
| library(data.table) | |
| library(SampleFile1415) | |
| as.data.table(sample_file_1415) %>% | |
| .[, tax_noCGT := Taxable_Income + Net_CG_amt] %>% | |
| .[, tax := income_tax(Taxable_Income, "2014-15", .dots.ATO = sample_file_1415)] %>% | |
| .[, tax_new := income_tax(tax_noCGT, "2014-15", .dots.ATO = sample_file_1415)] %>% | |
| .[, .(tot = round(50 * sum(tax_new - tax) / 1e9, 1))] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Quickly count the number of files in a directory | |
| number_of_files <- function(dir, filetype = "*.*") { | |
| if (.Platform$OS.type == "windows" && | |
| nzchar(Sys.which("powershell"))) { | |
| current_wd <- getwd() | |
| on.exit(setwd(current_wd)) | |
| setwd(dir) | |
| result <- system2("powershell", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| paste("gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer", | |
| "-dNOPAUSE -dQUIET -dBATCH", "-sOutputFile=output.pdf", | |
| "report-cover-energy-nem-latex.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| parse2 <- function(x) { | |
| # x <- "ab{c{f}}d{e}f{g}h{ij{{k}}}lm" | |
| x_split <- unlist(strsplit(x, "", fixed = TRUE)) | |
| tex_group <- cumsum(x_split == "{") - cumsum(x_split == "}") | |
| max_tex_group <- max(tex_group) | |
| out <- setDT(list(char = x_split, tex_group = tex_group)) | |
| out[, I := .I] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |