Skip to content

setlevels() doesn't handle missing or out-of-bounds factor values #7595

@sindribaldur

Description

@sindribaldur

I'm aware this is not something you should be doing but I guess crashing is not the best way out.

setattr(factor(c(1:3), levels = c("1", "2")), "levels", c("1", "1"))

System info (where it consistently crashes R).

> version
               _
platform       x86_64-w64-mingw32
arch           x86_64
os             mingw32
crt            ucrt
system         x86_64, mingw32
status
major          4
minor          5.1
year           2025
month          06
day            13
svn rev        88306
language       R
version.string R version 4.5.1 (2025-06-13 ucrt)
nickname       Great Square Root

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions