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 |
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
require('XML') | |
tess_studies_list <- function(){ | |
x <- xmlParse('http://www.tessexperiments.org/previousstudies.html') | |
} | |
get_tess_study <- function(id, file){ | |
download.file() | |
} |
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
# function definition | |
`%by%` <- function(a,b){ | |
s <- substitute(a) | |
l <- as.list(s) | |
p <- parse(text=s) | |
if(length(p)>2) { | |
l <- l[3:length(l)] | |
do.call("by", c(list(data=eval.parent(p[2]), | |
INDICES=b, | |
FUN=eval.parent(p[1])), |
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
rp <- function() { | |
stack <- numeric() | |
push <- function(values) stack <<- c(stack, values) | |
pop <- function() { | |
a <- stack[length(stack)] | |
stack <<- stack[-length(stack)] | |
return(a) | |
} | |
reverse <- function() { | |
r <- readline() |
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
1. Install GNU gettext (on Windows, this can be obtained from the Rtools site: http://www.stats.ox.ac.uk/pub/Rtools/goodies/gettext-tools.zip) | |
2. Run `update_pkg_po()` (https://stat.ethz.ch/R-manual/R-devel/library/tools/html/update_pkg_po.html) | |
a. Create `/po` if it does not exist | |
b. Call `xgettext2pot()` to create/update `po/R-pkgname.pot` file | |
c. All `R-lang.po` files in `/po` are updated from `po/R-pkgname.pot` using `msgmerge` | |
d. `checkPoFiles()` is called on updated files | |
e. If check is successful, messages are compiled using `msgfmt` system call and installed in `/inst/po`. | |
f. In a UTF-8 locale, a ‘translation’ ‘R-en@quot.po’ is created with UTF-8 directional quotes, compiled and installed under ‘inst/po’. | |
g. If `po/pkg.pot` exists: | |
i. `/src` is examined to create `/po/pkg.pot` |
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
#' Parse a codebook file with variable and level information. | |
#' | |
#' Parses a codebook file where lines starting at column zero (far left) represet | |
#' variable information (e.g. name, description, type) and indented lines | |
#' (i.e. lines beginning with white space, either tabs or spaces, etc.) represent factor | |
#' levels and labels. | |
#' | |
#' Note that white space at the beginning and end of each line is stripped before | |
#' processing that line. | |
#' |
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
read.fwf2 <- function (file, widths, header = FALSE, sep = "\t", skip = 0, | |
row.names, col.names, n = -1, ...) | |
{ | |
doone <- function(x) { | |
x <- substring(x, first, last) | |
x[!nzchar(x)] <- NA_character_ | |
paste0(x, collapse = sep) | |
} | |
if (is.list(widths)) { | |
recordlength <- length(widths) |
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
z <- function(data, FUN = mean, ...) aggregate(. ~ 1, data = data, FUN = FUN, ...) | |
y <- function(data, FUN = mean, ...) data.frame(t(apply(data, 2, FUN = FUN, ...))) | |
x <- function(data, FUN = mean, ...) data.frame(t(sapply(data, mean, ...))) | |
d1 <- data.frame(matrix(1e3, ncol=10)) | |
d2 <- data.frame(matrix(1e6, ncol=10)) | |
d3 <- data.frame(matrix(1e6, ncol=100)) | |
# MEAN |
OlderNewer