Skip to content

Instantly share code, notes, and snippets.

@mdlincoln
Last active Mar 7, 2016
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@mdlincoln mdlincoln commented Mar 4, 2016

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

@mdlincoln

This comment has been minimized.

Copy link
Owner Author

@mdlincoln mdlincoln commented Mar 7, 2016

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