Created
January 3, 2014 01:27
-
-
Save dfalster/8230860 to your computer and use it in GitHub Desktop.
Function to help write metadata for csv files. Assuming your headers are on line 1 of a file, this function takes the headers and transposes them, printing to a new file with suffix "metadata_" and with columns variable, units, description, notes
This file contains 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
csv_metadata <- function(filename){ | |
data <- read.csv(filename, stringsAsFactors=FALSE, fill=TRUE, header=TRUE, check.names = FALSE) | |
write.csv(data.frame(variable=names(data), units="",description="", notes=""), quote=TRUE, row.names=FALSE, | |
file = file.path(dirname(filename), paste0("metadata_",basename(filename)))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To apply to a series of files