Skip to content

Subsetting SE with factor() does not work #89

@TuomasBorman

Description

@TuomasBorman

Hi!

I noticed that trying to subset SE with factors lead to error that might be hard to solve. This problematic scenario can occur, for instance, if user has run some method that returns feature names as factors instead of characters (for example, table including results and feature names).

If user tries to select specified features based on factor, it leads to ambiguous error.

library(SummarizedExperiment)

counts <- matrix(
    1:4,
    nrow = 2,
    ncol = 2,
    dimnames = list(c("gene1", "gene2"), c("sample1", "sample2")
    )
)

se <- SummarizedExperiment(assays = list(counts = counts))
se["gene1", ]

se[factor("gene1"), ]

Error: cannot subset by character when rownames are NULL

Since SE converts factors to characters when setting row or column names, it may be reasonable to treat them as character variables also when subsetting.

-Tuomas

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