Skip to content

remove_labels does not work with tibbles #28

Description

@lefkiospaikousis

Hi! Thanks for your package. I 've been using it a lot and it significantly improves my workflow

I (accidentally) stumbled upon this small issue and thought I would I'd let you know

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

mtcars_df <- 
  mtcars %>% 
    dplyr::select(mpg:disp) %>% 
    sjlabelled::set_label(
      c("mileage", "cylinder","display")
    ) 

mtcars_tb <- 
  mtcars %>% 
    tibble::as_tibble() %>% 
    dplyr::select(mpg:disp) %>% 
    sjlabelled::set_label(
      c("mileage", "cylinder","display")
    ) 

dplyr::lst(mtcars_df, mtcars_tb) %>% purrr::map(~ class(.))
#> $mtcars_df
#> [1] "data.frame"
#> 
#> $mtcars_tb
#> [1] "tbl_df"     "tbl"        "data.frame"

mtcars_df %>% purrr::map(~ attributes(.))
#> $mpg
#> $mpg$label
#>       mpg 
#> "mileage" 
#> 
#> 
#> $cyl
#> $cyl$label
#>        cyl 
#> "cylinder" 
#> 
#> 
#> $disp
#> $disp$label
#>      disp 
#> "display"
mtcars_tb %>% purrr::map(~ attributes(.))
#> $mpg
#> $mpg$label
#>       mpg 
#> "mileage" 
#> 
#> 
#> $cyl
#> $cyl$label
#>        cyl 
#> "cylinder" 
#> 
#> 
#> $disp
#> $disp$label
#>      disp 
#> "display"

# REMOVE THE LABELS information and CHECK

mtcars_df %>% 
  finalfit::remove_labels() %>% 
  purrr::map(~ attributes(.))
#> $mpg
#> NULL
#> 
#> $cyl
#> NULL
#> 
#> $disp
#> NULL

mtcars_tb %>% 
  finalfit::remove_labels() %>% 
  purrr::map(~ attributes(.))
#> $mpg
#> $mpg$label
#>       mpg 
#> "mileage" 
#> 
#> 
#> $cyl
#> $cyl$label
#>        cyl 
#> "cylinder" 
#> 
#> 
#> $disp
#> $disp$label
#>      disp 
#> "display"

Created on 2019-10-23 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions