DOI-USGS / meddle

Tools for metadata creation and data releases
Other
0 stars 10 forks source link

write_attr_file should quote=TRUE #35

Closed aappling-usgs closed 6 years ago

aappling-usgs commented 7 years ago

I've entered text (including commas, so the text is in quotes) in my attr.csv file. My remake file calls attribute_skeleton again because I edited the number of rows in the input data.frame. My attr.csv file now has no quotes around the comma-containing text fields, so next time I try to read this file, read.table() throws an error.

I think the solution is simply to set quote=TRUE instead of quote=FALSE in the write.table calls in write_attr_file.

aappling-usgs commented 6 years ago

This happened to me again today, in stream_metab_usa where trying to rebuild a new site metadata table.

[ BUILD ] meta_all_df                                            |  meta_all_df <- combine_site_data(sb_meta_basic, sb_meta_dvqcoefs, sb_meta_struct, sites = meta...
[ BUILD ] ../4_data_release/in/site_data_attr.csv                |  attribute_skeleton(meta_all_df, "../4_data_release/in/site_data_attr.csv")
[ BUILD ] site_data_attr                                         |  site_data_attr <- as.attr_list("../4_data_release/in/site_data_attr.csv")
Error in read.table(filename, header = TRUE, sep = ",", stringsAsFactors = FALSE,  : 
  more columns than column names
> traceback()
22: stop("more columns than column names")
21: read.table(filename, header = TRUE, sep = ",", stringsAsFactors = FALSE, 
        ...) at read_data.R#51
20: read_data.csvfile(attr.file, check.names = FALSE, na.strings = " ") at read_data.R#9
19: read_data(attr.file, check.names = FALSE, na.strings = " ") at attribute-utils.R#74
18: read_attr_file(x) at attribute-utils.R#205
17: as.attr_list.character("../4_data_release/in/site_data_attr.csv") at attribute-utils.R#198
16: as.attr_list("../4_data_release/in/site_data_attr.csv")
15: eval(target$command, envir)

site_data_attr.csv gets rebuilt but without quotes around the elements (some of which contain commas), so when as.attr_list goes to read in the file, it's no longer readable as a csv.