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
library(devtools) | |
install_github("pckgA", "brodieg") # defines old class "file" and class union "fileOrNULL" == c("file", "NULL") | |
install_github("pckgB", "brodieg") # defines old class "file", and nothing else | |
library(pckgA) | |
makeDummy() # from pckgA, instantiates a class with a "fileOrNULL" slot, placing a temp file S3 object in the slot | |
library(pckgB) | |
makeDummy() # this fails now |
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
# Because there is no way to tell data.table | |
# "interpret this variable as a column name", it's possible to come up | |
# with corner cases. I'll grant these are unlikely to occur in day | |
# to day use, but any function that uses `data.table` must account for | |
# them | |
# Low odds, and yes, there are workarounds, but this is | |
# what I mean by you have to think carefully to avoid | |
# corner cases |
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
DT[ | |
id %in% 200:300, | |
.(reg.val = sum(value)), | |
by=region | |
][ | |
reg.val > 0, | |
range(reg.val) | |
] |
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
# Packages | |
library(devtools) | |
install_github("smbache/ensurer") | |
install_github("brodieg/alike") | |
library(ensurer) | |
library(alike) | |
library(magrittr) | |
set.seed(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
list(system=c("browser", | |
"device", | |
"dvipscmd", | |
"mailer", | |
"pager", | |
"pdfviewer", | |
"pkgType", | |
"printcmd", | |
"HTTPUserAgent", | |
"texi2dvi", |
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 |
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
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
# 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
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) { |
OlderNewer