[.safeframe | R Documentation |
The []
and [[]]
operators for safeframe
objects behaves like for
regular data.frame
or tibble
, but check that tagged variables are not
lost, and takes the appropriate action if this is the case (warning, error,
or ignore, depending on the general option set via lost_tags_action()
) .
## S3 method for class 'safeframe'
x[i, j, drop = FALSE]
## S3 replacement method for class 'safeframe'
x[i, j] <- value
## S3 replacement method for class 'safeframe'
x[[i, j]] <- value
## S3 replacement method for class 'safeframe'
x$name <- value
x |
a |
i |
a vector of |
j |
a vector of |
drop |
a |
value |
the replacement to be used for the entries identified in |
name |
a literal character string or a name (possibly backtick
quoted). For extraction, this is normally (see under
‘Environments’) partially matched to the |
If no drop is happening, a safeframe
. Otherwise an atomic vector.
lost_tags_action()
to set the behaviour to adopt when tags are
lost through subsetting; default is to issue a warning
get_lost_tags_action()
to check the current the behaviour
if (require(dplyr) && require(magrittr)) {
## create a safeframe
x <- cars %>%
make_safeframe(
mph = "speed",
distance = "dist"
) %>%
mutate(result = if_else(speed > 50, "fast", "slow")) %>%
set_tags(ticket = "result")
x
## dangerous removal of a tagged column setting it to NULL issues warning
x[, 1] <- NULL
x
x[[2]] <- NULL
x
x$speed <- NULL
x
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.