Skip to content

Should gather default to character instead of factor for the key column? #96

Description

@klmr

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions