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
# 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') |
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
# 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) |
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
# 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 |
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’ ‘[email protected]’ 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
read.qualtrics.csv <- function(filename, stringsAsFactors = FALSE, ...) { | |
n <- read.csv(filename, nrows = 1, stringsAsFactors = FALSE) | |
dat <- read.csv(filename, header = FALSE, skip = 2, stringsAsFactors = stringsAsFactors, ...) | |
names(dat) <- names(n) | |
names(dat)[1:10] <- n[1,1:10] | |
for(i in seq_along(dat)) { | |
attr(dat[,i], "question") <- n[1,i] | |
} | |
dat | |
} |