gather currently dispatches to reshape2::melt, and the resulting key column is of type factor, unless convert=TRUE is specified, in which case it’s converted to another type, depending on the actual data.
This default makes sense if the resulting table is used with modelling functions, but not much else. In particular, a very common workflow for me is to use gather followed by inner_join, e.g. (where counts is a gene expression experiment consisting of several libraries, and col_data is the experiment’s column data, in Bioconductor parlance, i.e. describes the experiments):
counts = gather(counts, Library, Count) %>% inner_join(col_data, by = 'Library')
This invariably yields a warning from inner_join:
joining factor and character vector, coercing into character vector
And while harmless, it’s a bit annoying, especially as this is usually in a knitr document and I don’t want to clutter my output.
convert=TRUE isn’t really what I want: For instance, I almost always want the result to be of type character, regardless of the actual data format.
Am I right in thinking that using factor rather than character as the type of the key column is more for historical reasons than actually due to a hard advantage? Would it make sense to change the default?
gathercurrently dispatches toreshape2::melt, and the resulting key column is of typefactor, unlessconvert=TRUEis specified, in which case it’s converted to another type, depending on the actual data.This default makes sense if the resulting table is used with modelling functions, but not much else. In particular, a very common workflow for me is to use
gatherfollowed byinner_join, e.g. (wherecountsis a gene expression experiment consisting of several libraries, andcol_datais the experiment’s column data, in Bioconductor parlance, i.e. describes the experiments):This invariably yields a warning from
inner_join:And while harmless, it’s a bit annoying, especially as this is usually in a knitr document and I don’t want to clutter my output.
convert=TRUEisn’t really what I want: For instance, I almost always want the result to be of typecharacter, regardless of the actual data format.Am I right in thinking that using
factorrather thancharacteras the type of the key column is more for historical reasons than actually due to a hard advantage? Would it make sense to change the default?