Skip to content

Instantly share code, notes, and snippets.

@mdlincoln
Last active March 7, 2016 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdlincoln/aee8452725d87921762d to your computer and use it in GitHub Desktop.
Save mdlincoln/aee8452725d87921762d to your computer and use it in GitHub Desktop.
Create a skeleton documentation string for an R data.frame
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)), "\"")
}
@mdlincoln
Copy link
Author

This works best when you pipe the output into write_clip() from clipr

@mdlincoln
Copy link
Author

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