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 hidden or 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)), "\"") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're using RStudio, there's a better variant as an addin: https://github.com/mdlincoln/docthis