modify.default | R Documentation |
Modifies the attributes of each indicated element (all elements by default). Tries to assign the value of an expression to the supplied label, with existing attributes and the object itself (.) available as arguments. Gives a warning if the supplied label is considered reserved. Intends to support anything with one or more non-empty names.
## Default S3 method:
modify(
x,
...,
.reserved = getOption("yamlet_modify_reserved", c("class", "levels", "labels",
"names"))
)
x |
object |
... |
indicated columns, or name-value pairs |
.reserved |
reserved labels that warn on assignment |
The name of the component itself is available during assignments as
attribute 'name' (any pre-existing attribute 'name' is temporarily masked).
After all assignments are complete, the value of 'name' is enforced at the object level.
Thus, modify
expressions can modify component names.
As currently implemented, the expression is evaluated by
eval_tidy
, with attributes supplied as
the data
argument. Thus, names in the expression
may be disambiguated, e.g. with .data
. See examples.
same class as x
Other modify:
modify()
,
named()
,
selected.default()
,
selected()
Other interface:
canonical.decorated()
,
classified.data.frame()
,
decorate.character()
,
decorate.data.frame()
,
desolve.decorated()
,
ggplot.decorated()
,
io_csv.character()
,
io_csv.data.frame()
,
io_res.character()
,
io_res.decorated()
,
io_table.character()
,
io_table.data.frame()
,
io_yamlet.character()
,
io_yamlet.data.frame()
,
is_parseable.default()
,
mimic.default()
,
promote.list()
,
read_yamlet()
,
resolve.decorated()
,
selected.default()
,
write_yamlet()
library(magrittr)
library(dplyr)
file <- system.file(package = 'yamlet', 'extdata','quinidine.csv')
x <- decorate(file)
# modify selected columns
x %<>% modify(title = paste(label, '(', guide, ')'), time)
x %>% select(time, conc) %>% decorations
# modify (almost) all columns
x %<>% modify(title = paste(label, '(', guide, ')'), -Subject)
x %>% select(time, conc) %>% decorations
# use column itself
x %<>% modify(`defined values` = sum(!is.na(.)))
x %>% select(time) %>% decorations
# rename column
x %<>% modify(time, name = label)
names(x)
# warn if assignment fails
## Not run:
\donttest{
x %<>% modify(title = foo, time)
}
## End(Not run)
# support lists
list(a = 1, b = 1:10, c = letters) %>%
modify(length = length(.), b:c)
x %<>% select(Subject) %>% modify(label = NULL, `defined values` = NULL)
# distinguish data and environment
location <- 'environment'
x %>% modify(where = location) %>% decorations
x %>% modify(where = .env$location) %>% decorations
## Not run:
\donttest{
x%>% modify(where = .data$location) %>% decorations
}
## End(Not run)
x %>% modify(location = 'attributes', where = location) %>% decorations
x %>% modify(location = 'attributes', where = .data$location) %>% decorations
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.