Skip to content

Instantly share code, notes, and snippets.

View leeper's full-sized avatar

Thomas J. Leeper leeper

View GitHub Profile
@leeper
leeper / ShinyPerspectivePlot.R
Last active November 9, 2021 10:26
Shiny App for 3D Interaction plots
library("shiny")
library("shinyjs")
ui <- shinyUI(pageWithSidebar(
titlePanel("", "3D Perspective Plot for Interaction Effects"),
sidebarPanel(
tabsetPanel(
tabPanel("Data",
# setup
library("survey")
data("api")
apiclus1$proportion <- apiclus1$pcttest/100
dclus1<-svydesign(id=~dnum, fpc=~fpc, data=apiclus1)
# confint(svymean(...) == svyciprop(..., method = "me")
confint(svymean(~ proportion, dclus1))
## 2.5 % 97.5 %
## proportion 0.9852196 0.9943432
@leeper
leeper / winbuild.txt
Last active July 25, 2021 02:36
Building R from source on Windows
# Outline for building R from source on Windows (7)
# http://cran.r-project.org/doc/manuals/r-release/R-admin.html#Building-from-source
# Pre-built Windows R-Devel binary: http://cran.r-project.org/bin/windows/base/rdevel.html
# possibly helpful: http://stackoverflow.com/questions/25451705/build-r-source-code-from-windows
# install Rtools
# http://cran.r-project.org/bin/windows/Rtools/
# install Inno Setup (Unicode version)
@leeper
leeper / stata_summary.R
Created February 21, 2018 10:53
Stata-style regression summaries
stata_summary <-
function(
x,
...
) {
# summarize
mod <- x
x <- summary(x)
# find outcome variable
@leeper
leeper / ttttable.R
Last active May 19, 2021 22:38
Grammar of Tables?
# ttable: a grammar of tables
# https://gist.github.com/leeper/f9cfbe6bd185763762e126a4d8d7c286
# aggregate/summarize
# arrange
# annotation (metadata features)
# theme
@leeper
leeper / update_github.R
Last active February 2, 2021 22:56
Update packages if a newer version is available from GitHub
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)
@leeper
leeper / pushpop.R
Last active January 5, 2021 18:51
One-line push and pop in R
# push
push <- function(x, values) (assign(as.character(substitute(x)), c(x, values), parent.frame()))
# pop
pop <- function(x) (assign(as.character(substitute(x)), x[-length(x)], parent.frame()))
# example
z <- 1:3
push(z, 4)
z
@leeper
leeper / google_dmca.R
Last active February 18, 2020 17:51
Quick analysis of Google's DMCA Data
# Google DMCA Transparency Data
# 2014-07-24
# https://www.google.com/transparencyreport/removals/copyright/data/
# get the data
download.file('http://transparencyreport.storage.googleapis.com/google-websearch-copyright-removals.zip',
'localcopy.zip', method = 'curl')
unzip('localcopy.zip', files = 'google-websearch-copyright-removals/requests.csv')
@leeper
leeper / word_count.R
Created August 16, 2018 22:07
R function to obtain a word count from a PDF
# Copyright (c) 2018 Thomas J. Leeper
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@leeper
leeper / WindowsThings
Last active November 18, 2019 14:47
Things I like installed on my Windows laptop
thing,chocolatey_name
Adobe Reader,adobereader
ccleaner,ccleaner
chocolatey,
Chrome,google-chrome-x64
ConEmu,conemu
curl,curl
cutepdf,cutepdf
Dropbox,dropbox
gettext,