A selector function to use in tidyverse functions
Note
Using this in a pipeline results in a 'safeframe' object, but does not maintain the variable labels at this time. It is primarily useful to make your pipelines human readable.
Examples
## create safeframe
x <- make_safeframe(cars,
speed = "Miles per hour",
dist = "Distance in miles"
)
head(x)
#>
#> // safeframe object
#> speed dist
#> 1 4 2
#> 2 4 10
#> 3 7 4
#> 4 7 22
#> 5 8 16
#> 6 9 10
#>
#> labelled variables:
#> speed - Miles per hour
#> dist - Distance in miles
if (require(dplyr) && require(magrittr)) {
x %>%
select(has_label(c("Miles per hour", "Distance in miles"))) %>%
head()
}
#> Loading required package: 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
#> Loading required package: magrittr
#>
#> // safeframe object
#> speed dist
#> 1 4 2
#> 2 4 10
#> 3 7 4
#> 4 7 22
#> 5 8 16
#> 6 9 10
#>
#> labelled variables:
#> speed - Miles per hour
#> dist - Distance in miles