Skip to content

discard removes list() attributes? #148

@bblodfon

Description

@bblodfon

I think this is unwanted behaviour, as discard should only act on the elements of the list?

library(mlr3misc) # 0.19.0

res = list(a = 1, b = "tree")
attr(res, "my_attr") = "some_value"
res # has the attribute
#> $a
#> [1] 1
#> 
#> $b
#> [1] "tree"
#> 
#> attr(,"my_attr")
#> [1] "some_value"

r = mlr3misc::discard(res, is.numeric)
r # extra attribute is removed!
#> $b
#> [1] "tree"
attributes(r)
#> $names
#> [1] "b"

Created on 2025-09-23 with reprex v2.1.1

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