#' Create a bare metadata file from a dataframe that you plan to save as a csv file
#'
#' @description Generates a metadata file that matches the emLab SOP that is completely bare apart from the absolute basics
#'
#' @param x dataframe in your R environment that you'd like to create a metadata file for
#' @param file string for the filename that you plan to save (must match the filename you used to save the .csv but sans the ".csv" bit)
#' @param path directory for where the readme will be saved) (e.g. "Downloads/")
#'
#' @importFrom readxl read_excel
#' @importFrom utils read.csv head
#'
#' @export
#'
create_metadataB <- function(x, file = NULL, path = ".") {
filename <- paste0("_readme_", file, ".txt")
date <- Sys.Date()
name <- Sys.getenv("USER")
sink(file.path(path, filename), append = FALSE)
writeLines(c("This ", filename," file was generated on ", paste(date), " by ", name), sep = "")
writeLines("")
writeLines("\n--------------------------")
writeLines("\nGENERAL INFORMATION")
writeLines("\n--------------------------")
writeLines("\n")
writeLines(c("\nTitle of Dataset:", gsub(".csv", "", gsub("_|-", " ", file))), sep = " ")
writeLines("\n")
writeLines(c("\nAuthor Information:", name), sep = " ")
writeLines("\n")
writeLines(c("\n\t Principal Investigator:"), sep = " ")
writeLines(c("\n\t Associate or Co-investigator:"), sep = " ")
writeLines(c("\n\t Primary Contact:"), sep = " ")
writeLines(c("\n\t Alternate Contact(s):"), sep = " ")
writeLines("\n")
writeLines(c("\nDate of data collection:", paste(date)), sep = " ")
writeLines("\n")
writeLines(c("\nGeographic location of data collection:"), sep = " ")
writeLines("\n")
writeLines(c("\nInformation about funding sources or sponsorship that supported the collection of the data:"), sep = " ")
writeLines("\n")
writeLines("\n--------------------------")
writeLines("\nPROJECT INFORMATION")
writeLines("\n--------------------------")
writeLines("\n")
writeLines(c("\nProject name:"), sep = " ")
writeLines("\n")
writeLines(c("\nProject Description:"), sep = " ")
writeLines("\n")
writeLines(c("\nGitHub:"), sep = " ")
writeLines("\n")
writeLines("\n--------------------------")
writeLines("\nSHARING/ACCESS INFORMATION")
writeLines("\n--------------------------")
writeLines("\n")
writeLines(c("\nLicenses/restrictions placed on the data, or limitations of reuse:"), sep = " ")
writeLines("\n")
writeLines(c("\nRecommended citation for the data:"), sep = " ")
writeLines("\n")
writeLines(c("\nCitation for and links to publications that cite or use the data:"), sep = " ")
writeLines("\n")
writeLines(c("\nLinks to other publicly accessible locations of the data:"), sep = " ")
writeLines("\n")
writeLines(c("\nLinks/relationships to ancillary or related data sets:"), sep = " ")
writeLines("\n")
writeLines("\n--------------------------")
writeLines("\nDATA DESCRIPTION & FILE OVERVIEW")
writeLines("\n--------------------------")
writeLines("\n")
writeLines(c("\nDescription:"), sep = " ")
writeLines("\n")
writeLines(c("\nFile list:"), sep = " ")
writeLines("\n")
writeLines(c("\nRelationship between files, if important for context:"), sep = " ")
writeLines("\n")
writeLines(c("\nIf data was derived from another source, list source:"), sep = " ")
writeLines("\n")
writeLines(c("\nIf there are there multiple versions of the dataset, list the file updated, when and why update was made:"), sep = " ")
writeLines("\n")
writeLines("\n--------------------------")
writeLines("\nMETHODOLOGICAL INFORMATION")
writeLines("\n--------------------------")
writeLines("\n")
writeLines(c("\nDescription of methods used for collection/generation of data:"), sep = " ")
writeLines("\n")
writeLines(c("\nLinks for method descriptions:"), sep = " ")
writeLines("\n")
writeLines(c("\nMethods for processing the data:"), sep = " ")
writeLines("\n")
writeLines(c("\nDescribe any quality-assurance procedures performed on the data:"), sep = " ")
writeLines("\n")
writeLines(c("\nPeople involved with sample collection, processing, analysis and/or submission:"), sep = " ")
writeLines("\n")
writeLines("\n--------------------------")
writeLines("\nDATA SPECIFIC INFORMATION")
writeLines("\n--------------------------")
writeLines("\n")
writeLines(c("\nNumber of variables:", ncol(x)), sep = " ")
writeLines(c("\nNumber of cases/rows:", nrow(x)), sep = " ")
writeLines(c("\nColumns:"), sep = " ")
for(val in 1:ncol(x)) {
writeLines(c("\n\t",names(x)[val]), sep = " ")
writeLines(c("\n\t\tDescription:"), sep = " ")
writeLines(c("\n\t\tUnits/Format:"), sep = " ")
writeLines(c("\n\t\tData Class:", paste(class(x[[val]]), collapse = ", ")), sep = " ")
writeLines(c("\n\t\tExample Values:",paste(utils::head(unique(x[[val]]), n = 3))), sep = " ")
}
writeLines("\n")
writeLines(c("\nMissing data codes:"), sep = " ")
writeLines(c("\nSpecialized formats or other abbreviations used:"), sep = " ")
sink()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.