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
# Draw R expressions as ascii trees | |
library(stringr) | |
library(testthat) # for the colourise function | |
str_trunc <- function(x, width = getOption("width")) { | |
ifelse(str_length(x) <= width, x, str_c(str_sub(x, 1, width - 3), "...")) | |
} | |
is.constant <- function(x) !is.language(x) | |
is.leaf <- function(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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style></style> | |
<body> | |
<script src="http://d3js.org/d3.v2.min.js?2.9.6"></script> | |
<script src="http://coffeescript.org/extras/coffee-script.js"></script> | |
<script src="table.coffee" type="text/coffeescript"></script> |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style></style> | |
<body> | |
<script src="http://d3js.org/d3.v2.js?2.9.6"></script> | |
<script src="http://coffeescript.org/extras/coffee-script.js"></script> | |
<script src="vis.coffee" type="text/coffeescript"></script> | |
<svg width="400" height="400" id="chart"></svg> |
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
with(x, { | |
f(z) | |
}) | |
# Which of the following statements is this equivalent to? | |
# | |
# a) x$f(x$z) | |
# b) f(x$z) | |
# c) x$f(z) | |
# d) f(z) |
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(tm) | |
x <- paste(sample(c(LETTERS, " "), 1e4, rep = T), collapse = "") | |
words <- stopwords("english") | |
match <- sprintf("\\b(%s)\\b", paste(words, collapse = "|")) | |
system.time(gsub(match, "", x)) | |
# Takes ~0.08 s | |
# Home made solution, not quite equivalent but close. |
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(stringr) | |
library(tm) | |
if (file.exists("english.rds")) { | |
data <- readRDS("english.rds") | |
} else { | |
data <- read.csv("english_text.csv.gz", stringsAsFactors = FALSE) | |
saveRDS(data, "english.rds") | |
} |
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
#include <R.h> | |
#include <Rdefines.h> | |
#ifdef WIN32 | |
#include <shlobj.h> | |
// SHGetFolderPath documentation: | |
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181.aspx | |
SEXP get_folder_path() { |
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
vertoccurrence <- function(key="r_B68F3", grp="fish", t = NULL, l = NULL, | |
c = NULL, d = NULL, q = NULL, p = NULL, m = NULL, cols = NULL, num = NULL, | |
set = NULL) | |
{ | |
grp <- match.arg(grp, c("bird", "herp", "fish")) | |
url <- c( | |
bird = "http://ornis2.ornisnet.org/api/v1/occurrence/?", | |
herp = "http://herpnet2.org/api/v1/occurrence/?", | |
fish = "http://www.fishnet2.net/api/v1/occurrence/?" | |
)[grp] |
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
# OR with httr | |
library(httr) | |
vertoccurrence <- function(key="r_B68F3", grp="fish", t = NULL, l = NULL, | |
c = NULL, d = NULL, q = NULL, p = NULL, m = NULL, cols = NULL, num = NULL, | |
set = NULL) | |
{ | |
grp <- match.arg(grp, c("bird", "herp", "fish")) | |
url <- c( | |
bird = "http://ornis2.ornisnet.org/api/v1/occurrence/", |
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
document <- function(pkg = NULL, clean = FALSE, roclets = c("collate", "namespace", "rd")) { | |
require("roxygen2") | |
man_path <- file.path(pkg$path) | |
if (!file.path(pkg$path)) dir.create(man_path) | |
message("Updating ", pkg$package, " documentation") | |
pkg <- as.package(pkg) | |
if (clean) { | |
clear_caches() |