Last active
March 7, 2016 19:39
-
-
Save mdlincoln/aee8452725d87921762d to your computer and use it in GitHub Desktop.
Create a skeleton documentation string for an R data.frame
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
doc_data <- function(d) { | |
# Get column names and types | |
vartype <- vapply(d, typeof, FUN.VALUE = character(1)) | |
# Write individual item description templates | |
items <- paste0("#\' \\item{\\code{", names(vartype), "}}{", vartype, ". ###}", collapse = "\n") | |
# Return the full documentation template | |
paste0("#\' DATASET TITLE | |
#\' | |
#\' DATASET DETAILS | |
#\' | |
#\' @format A data frame with ", nrow(d), " rows and ", length(vartype), " variables: | |
#\' \\describe{ | |
", items, " | |
#\' } | |
\"", deparse(substitute(d)), "\"") | |
} |
If you're using RStudio, there's a better variant as an addin: https://github.com/mdlincoln/docthis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works best when you pipe the output into
write_clip()
from clipr