Learn R Programming

yamlet (version 0.6.5)

modify.default: Modify Attributes of Indicated Components by Default

Description

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.

Usage

# S3 method for default
modify(
  x,
  ...,
  .reserved = getOption("yamlet_modify_reserved", c("class", "levels", "labels",
    "names"))
)

Arguments

x

object

...

indicated columns, or name-value pairs

.reserved

reserved labels that warn on assignment

Value

same class as x

Details

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.

See Also

Other modify: modify(), named(), selected.default(), selected()

Other interface: classified.data.frame(), decorate.character(), decorate.data.frame(), desolve.decorated(), ggplot.decorated(), io_csv.character(), io_csv.data.frame(), io_res.character(), io_table.character(), io_table.data.frame(), io_yamlet.character(), io_yamlet.data.frame(), is_parseable.default(), mimic.default(), promote.default(), read_yamlet(), resolve.decorated(), selected.default(), write_yamlet()

Examples

Run this code
# NOT RUN {
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)
}
# }
# NOT RUN {
# support lists
list(a = 1, b = 1:10, c = letters) %>%
modify(length = length(.), b:c)

# }

Run the code above in your browser using DataLab