Skip to content

coerceAs may be doing factor coercion incorrectly #6140

Closed

Description

@MichaelChirico

As seen in r-cmd-check-occasional:

test(10.16, coerceAs(1:2, factor(c("x","y"))), factor(c("x","y")), output="integer[integer] into integer[factor]")

When run in a locale where y sorts before x we get:

> x = coerceAs(1:2, factor(c("x", "y"))) 
First 2 of 2 (type 'integer'): 
[1] y x
Levels: y x
> y = factor(c("x", "y")) 
First 2 of 2 (type 'integer'): 
[1] x y
Levels: y x
2 string mismatches

I am not sure the intended behavior in this case, but that output does look potentially off to me. We can fix the test if the behavior is intentional, want to check with Jan first.

Activity

  1. jangorecki commented on May 19, 2024

    @jangorecki
    Member

    Locale was never considered when implementing this or adding this tests so it is not by design

  2. MichaelChirico commented on May 19, 2024

    @MichaelChirico
    MemberAuthor

    OK, so is it an error or intended?

    I lean towards "data.table always uses C locale to sort, including for generating factor levels automatically" as being the correct behavior, WDYT?

  3. jangorecki commented on May 20, 2024

    @jangorecki
    Member

    yes, agree

  4. added
    encoding
    and removed
    encoding
    on May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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