Skip to content

Instantly share code, notes, and snippets.

@gmbecker
gmbecker / vignCovSketch.R
Created February 20, 2015 23:38
Vignette coverage code sketch
library(devtools) # someday this will be switchr ;-)
install_github("duncantl/CodeDepends")
library(knitr)
library(CodeDepends)
## package you're dealing with (pkgname) MUST be loaded before calling this
vignetteCoverage = function(pkgdir, pkgname = basename(pkgdir), vignexts = c(".Rmd", ".Rnw")) {
vigns = list.files(file.path(pkgdir, "vignettes"), pattern = paste0("(", paste(vignexts, collapse="|"), ")"), full.names=TRUE)
tmpfils = sapply(seq(along=vigns), function(x) tempfile( fileext=".R"))
rfils = mapply(function(inp, out) knit(inp, out, tangle=TRUE), inp = vigns, out = tmpfils)
@gmbecker
gmbecker / fancystopifnot.Rmd
Created February 9, 2015 19:21
fancystopifnot
```{r}
fancystopifnot = function(obj, condfun) {
x = capture.output(str(obj))
if(!condfun(obj)) stop(paste(c("Condition not met, got", x),
collapse = "\n\t"))}
fancystopifnot(data.frame(x = sample(1:100, 10),
y = sample(c("a", "b"), 10, replace=TRUE)),
is.integer)
```
@gmbecker
gmbecker / sessionInfo.txt
Last active August 29, 2015 14:14
match.call and do.call
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C