While working on a project on data imported from .sav file I found that creating variable labels helped my workflow. I would like to store these labels in a file, together with the data itself, for future reference and collaboration. My question is if there is any way to do that without creating a separate file for the labels?
I am currently storing these labels in R as data frame attributes. A working example would be:
my.data <- data.frame(x = 1:10,y = 11:20)
attributes(my.data)$variable.labels <- c("numbers ranging from 1 to 10",
"numbers ranging from 11 to 20")
My current solution is saving the data and attributes as two separate files like so:
write.csv2(my.data, file = "my_data.csv")
write.csv2(attributes(my.data)$variable.labels, file = "my_data_attr.csv")
The problem I am having with this approach is that saving and than loading two files simultaneously is cumbersome and error-prone. I understand I could try to save it in a .sav file, but I would like the file to be editable with an accessible with spreadsheet software like MS EXCEL or equivalent so the people with whom I collaborate can make corrections and additions.
I was thinking of trying to add metadata by inserting comments in .csv like suggested in this question Python: skip comment lines marked with # in csv.DictReader or trying use .xml like in this blog post (http://blog.mafr.de/2008/04/26/metadata-for-csv/), but I don't know how to implement any of these in R, and am not sure in what way it will be editable with a spreadsheet afterwards.