This function converts a data.frame
or a tibble
into a safeframe
object, where data are tagged and validated. The output will seem to be the
same data.frame
, but safeframe
-aware packages will then be able to
automatically use tagged fields for further data cleaning and analysis.
Arguments
- x
a
data.frame
or atibble
- ...
<
dynamic-dots
> A named list with variable names inx
as list names and the tags as list values. Values set toNULL
remove the tag When specifying tags, please also seedefault_values
.
See also
An overview of the safeframe package
tags()
: for a list of tagged variables in asafeframe
set_tags()
: for modifying tagstags_df()
: for selecting variables by tags
Examples
x <- make_safeframe(cars,
speed = "Miles per hour",
dist = "Distance in miles"
)
## print result - just first few entries
head(x)
#>
#> // safeframe object
#> speed dist
#> 1 4 2
#> 2 4 10
#> 3 7 4
#> 4 7 22
#> 5 8 16
#> 6 9 10
#>
#> tagged variables:
#> speed - Miles per hour
#> dist - Distance in miles
## check tags
tags(x)
#> $speed
#> [1] "Miles per hour"
#>
#> $dist
#> [1] "Distance in miles"
#>
## tags can also be passed as a list with the splice operator (!!!)
my_tags <- list(
speed = "Miles per hour",
dist = "Distance in miles"
)
new_x <- make_safeframe(cars, !!!my_tags)
## The output is strictly equivalent to the previous one
identical(x, new_x)
#> [1] TRUE