Skip to content

Instantly share code, notes, and snippets.

@rmflight
Created October 9, 2012 13:54
Show Gist options
  • Save rmflight/3858973 to your computer and use it in GitHub Desktop.
Save rmflight/3858973 to your computer and use it in GitHub Desktop.
knitr table and figure functions for Rmd
pasteLabel <- function(preText, inObj, objName, insLink=TRUE){
objNum <- inObj[objName]
useText <- paste(preText, objNum, sep=" ")
if (insLink){
useText <- paste("[", useText, "](#", objName, ")", sep="")
}
useText
}
# this increments the counter, and gives a name to the number so we can reference it later
incCount <- function(inObj, useName){
nObj <- length(inObj)
useNum <- max(inObj) + 1
inObj <- c(inObj, useNum)
names(inObj)[nObj+1] <- useName
inObj
}
figCount <- c("_"=0)
tableCount <- c("_"=0)
tableCat <- function(inFrame){
outText <- paste(names(inFrame), collapse=" | ")
outText <- c(outText, paste(rep("---", ncol(inFrame)), collapse=" | "))
invisible(apply(inFrame, 1, function(inRow){
outText <<- c(outText, paste(inRow, collapse=" | "))
}))
return(outText)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment