Skip to content

glimpse confuses factors with commas in levels #384

Closed

Description

@alistaire47

I suspect it's a rare case, but because glimpse doesn't quote factors like it does strings, if the factor level has a comma in it, it looks like they're two observations, e.g.

library(tibble)

glimpse(
    tibble(x = factor(c('foo, bar', 'baz')),
           y = factor(c('hello, world', 'howdy'), ordered = TRUE),
           z = c('foo, bar', 'baz'))
)
#> Observations: 2
#> Variables: 3
#> $ x <fct> foo, bar, baz
#> $ y <ord> hello, world, howdy
#> $ z <chr> "foo, bar", "baz"

The evident solution would be to quote levels. Factors would be less differentiable from strings, though no worse than integers that happen to be stored as doubles, e.g. mtcars$gear.

Activity

  1. anhqle commented on Feb 28, 2018

    @anhqle
    Contributor

    @krlmlr what's your take on quoting factor levels (i.e. with "level")? Or perhaps quote using backticks?

  2. krlmlr commented on Mar 1, 2018

    @krlmlr
    Member

    I think we should use regular quotes here.

  3. added a commit that references this issue on Mar 1, 2018
    5d541d1
  4. added a commit that references this issue on Apr 24, 2018
    7709cfd
  5. added a commit that references this issue on May 23, 2018
  6. github-actions commented on Dec 11, 2020

    @github-actions
    Contributor

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

  7. locked and limited conversation to collaborators on Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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