Skip to content

Instantly share code, notes, and snippets.

@benjamin-chan
Last active May 23, 2016 23:20
Show Gist options
  • Save benjamin-chan/091209ab4eee1f171540 to your computer and use it in GitHub Desktop.
Save benjamin-chan/091209ab4eee1f171540 to your computer and use it in GitHub Desktop.
Function to create metadata object
makeMetadata <- function(D, note=NULL) {
if (is.data.frame(D)) {
list(objectName = deparse(substitute(D)),
timeStamp = sprintf("%s", Sys.time()),
objectSize = format(object.size(D), units="auto"),
note = note,
rowCount = nrow(D),
colCount = ncol(D),
colNames = names(D),
colClasses = sapply(D, class),
sysInfo = Sys.info(),
sessionInfo = sessionInfo())
} else {
warning(sprintf("Object %s is not a data.frame", deparse(substitute(D))))
}
}
# Examples:
# makeMetadata(cars)
# x <- 1
# makeMetadata(x) # Returns a warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment