Created
February 20, 2015 23:38
-
-
Save gmbecker/a1d6ce1e54ef24b194bf to your computer and use it in GitHub Desktop.
Vignette coverage code sketch
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) # 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) | |
scrinfs = lapply(rfils, function(x) { | |
scr = readScript(x) | |
scriptInfo(scr) | |
} ) | |
funs = unlist(lapply(scrinfs, function(x) lapply(x, function(y) names(y@functions)))) | |
symbs = ls(paste0("package:", pkgname)) | |
funs = funs[funs %in% symbs] | |
list(covered = funs, noncovered = symbs[!symbs %in% funs]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment