Skip to content

filter() removes labels from glue variables #7630

@d-morrison

Description

@d-morrison

Here's a reprex:

library(labelled)
library(glue)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
test = tibble(
  a = 1 |> set_label_attribute("a1"),
  b = glue::glue("two") |> set_label_attribute("b2")
)
test$b |> get_label_attribute()
#> [1] "b2"

# filter() strips the variable label from column `b`
dplyr::filter(test)$b |> get_label_attribute()
#> NULL

# filter() doesn't strip the label from column `a`
dplyr::filter(test)$a |> get_label_attribute()
#> [1] "a1"

Created on 2025-01-28 with reprex v2.1.1

I expected column b to keep its label attribute. Not sure if this is ultimately an issue with dplyr, glue, or labelled, but seems like it's in dplyr?

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