This file contains 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
# R Function to Draw Edward Tufte-style Slopeplots | |
slopegraph <- | |
function( | |
df, | |
xlim = c(.5,ncol(df)+.5), | |
ylim = c(min(df)-diff(range(df))/100,max(df)+diff(range(df))/100), | |
main = NULL, | |
bty = 'n', | |
yaxt = 'n', |
This file contains 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
# Drop shadows | |
# some data | |
x <- cbind(c(2,3,3,4,5,3,2), | |
c(3,3,5,4,3,2,1), | |
c(1,2,1,2,2,3,6)) | |
# Dark backdrop | |
# set plot background to black | |
par(bg='black', col.axis='white', col.lab='white', |
This file contains 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
# Sweave Compilation Shell Script | |
# Thomas J. Leeper | |
# Created 2011-08-12 | |
# Updated 2012-08-29 | |
# Copyright (C) 2012 Thomas J. Leeper | |
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. | |
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
sink("execute.log",split=FALSE,type = c("output", "message")) #Optional save shell script output |
This file contains 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
#' Gets gender by name or email address, optionally by country or IP address. | |
library("httr") | |
library("XML") | |
#' @import httr | |
#' @import rjson | |
#' @param name A character string containing a first name, or a character vector containing first names. One must specify name or email. | |
#' @param email A character string containing an email address with a first name. One must specify name or email. | |
#' @param country An optional character string containing a two-letter country name, as listed here: https://gender-api.com/en/api-docs |
This file contains 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
#' The goals here are to: | |
#' (1) play around with themes to make base graphics less ugly | |
#' (2) atomically specify multiple plot aspects (data, axes, grid, title) in a single call | |
#' (3) Recycle last plot theme to easily duplicate its appearance in the next plot | |
#' The idea is to create a set of customizable functions like `theme()`, which return a list of graphics arguments | |
#' These can then be passed to `splot`, which will cleanly handle them by passing some to `par` and some to `plot` | |
#' Different `theme()` functions can then be used to modify color palettes, axes, etc. | |
merge.list <- | |
function (x, y) { |
This file contains 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("RCurl") | |
library("RJSONIO") | |
catfacts <- function(number=1){ | |
if(is.null(number) || is.na(as.numeric(number)) || number < 1) | |
stop("'number' must be a positive integer") | |
fromJSON(getURL(paste('http://catfacts-api.appspot.com/api/facts?number=', number, sep='')))$facts | |
} | |
This file contains 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('devtools') | |
library('utils') | |
library('httr') | |
update_github <- | |
function(ask = TRUE, ...){ | |
installed <- installed.packages() | |
oldVersion <- installed[,'Version'] | |
urls <- sapply(names(oldVersion), function(x){ | |
d <- packageDescription(x) |
This file contains 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
# This is an effort to emulate Stata's `lookfor` in R | |
lookfor <- function(what, ls_opts = list(), ...){ | |
s <- do.call("ls", ls_opts) | |
d <- lapply(s, lookin, what = what, ...) | |
# return value should be a list with the string matching the search, along with details of its position | |
# big challenge is doing this recursively because, e.g., lists of lists of dataframes would be really difficult to search | |
class(d) <- 'lookfor' |
This file contains 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
# https://www.federalregister.gov/developers/api/v1 | |
# NAMESPACE | |
# importFrom(RJSONIO, fromJSON) | |
# importFrom(RCurl, curlPerform, basicTextGatherer) | |
# S3method(print,fedreg_document) | |
# S3method(print,fedreg_agency) | |
fr_search <- function(version='v1', ...) { |
This file contains 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
# call package easyio | |
library('foreign') | |
library('tools') | |
# library('haven') # for spss (sav, por), stata (dta), sas | |
#library('memisc') # for `spss.portable.file` and `spss.system.file` | |
#library('hmisc') # for `spss.get` | |
#library('openxlsx') # for `read.xlsx` | |
#library('data.table') # for fread |
OlderNewer