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
list.A <- list( | |
list(a=1, b=2, c=matrix(1:9, 3)), | |
letters[1:16], | |
1:100, | |
head(warpbreaks, 3) | |
) | |
list.B <- list.A | |
list.B[[1]]$a <- list() | |
list.B[[1]]$c <- list.B[[1]]$c[-1, ] | |
list.B[[2]] <- LETTERS[1:16] |
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
# Tested on OS X and Ubuntu R 3.3.1, appears fixed in R-devel | |
# WARNING: you may have to kill your session if you run the code here | |
fun <- function() { | |
on.exit(cat('exited\n')) | |
stop('hello') | |
} | |
{ | |
browser() | |
# type `fun()` at Browser[1]> prompt to cause infinite loop |
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
f1 <- tempfile() | |
f2 <- tempfile() | |
cat("hello\n", file=f1) | |
cat("goodbye\n", file=f2) | |
con1 <- file(f1) | |
open(con1) | |
getAllConnections() | |
close(con1) |
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
## Lightly edited for clarity | |
R version 3.2.2 (2015-08-14) -- "Fire Safety" | |
> install.packages("crayon") | |
trying URL 'http://cran.r-project.org/bin/macosx/mavericks/contrib/3.2/crayon_1.3.1.tgz' | |
Content type 'application/x-gzip' length 604079 bytes (589 KB) | |
================================================== | |
downloaded 589 KB |
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
ls(all=T) | |
# character(0) | |
install.packages("crayon") | |
# trying URL 'http://cran.r-project.org/bin/macosx/mavericks/contrib/3.2/crayon_1.3.1.tgz' | |
# Content type 'application/x-gzip' length 604079 bytes (589 KB) | |
# ================================================== | |
# downloaded 589 KB | |
# | |
# | |
# The downloaded binary packages are in |
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
diff_rdiff <- function(target, current) { | |
stopifnot(is.character(target), is.character(current)) | |
a <- tempfile("unitizerRdiffa") | |
writeLines(target, a) | |
b <- tempfile("unitizerRdiffb") | |
writeLines(current, b) | |
diff <- capture.output(system(paste("diff -bw", shQuote(a), shQuote(b)))) | |
} | |
differ <- function(A, B) { |
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
# http://stackoverflow.com/a/30781090/2725969 | |
sample0110b <- function(size, n) { | |
size <- as.integer(size) | |
n <- as.integer(n) | |
if(size > 25 || size < 3L) stop("Size out of valid range") | |
# Generate integer pool and weights |
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
sample01101 <- function(size, n, complete.only=FALSE) { | |
size <- as.integer(size) | |
n <- as.integer(n) | |
if(size > 25 || size < 3L) stop( | |
"Currently size min is 3 and max is 25, though should be possible to allow ", | |
"smaller and larger with some changes" | |
) | |
# Generate integer pool and weights |
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
make_pool <- function(size) | |
sort( | |
unlist( | |
lapply( | |
seq_len(size), | |
function(x) do.call(paste0, expand.grid(rep(list(c('0', '1')), x))) | |
) ) ) | |
system.time(pool4 <- make_pool(4)) |
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
sample0110 <- function(size, n, complete.only=FALSE) { | |
size <- as.integer(size) | |
n <- as.integer(n) | |
if(size > 25 || size < 3L) stop( | |
"Currently size min is 3 and max is 25, though should be possible to allow ", | |
"smaller and larger with some changes" | |
) | |
# Generate integer pool and weights |