conditionalize.data.frame: Conditionalize Attributes of Data Frame

View source: R/conditionalize.R

conditionalize.data.frameR Documentation

Conditionalize Attributes of Data Frame

Description

Conditionalizes attributes of data.frame. Creates a conditional attribute definition for column by mapping value to test. Only considers records where both test and value are defined, and gives an error if there is not one-to-one mapping. Can be used with write methods as an alternative to hand-coding conditional metadata.

Usage

## S3 method for class 'data.frame'
conditionalize(x, column, attribute, test, value, ...)

Arguments

x

data.frame

column

unquoted name of column to conditionalize

attribute

unquoted name of attribute to create for column

test

unquoted name of column to test

value

unquoted name of column supplying attribute value

...

ignored arguments

Details

If the test column is character, individual elements should not contain both single and double quotes. For the conditional expressions, these values will be single-quoted by default, or double-quoted if they contain single quotes.

Value

class 'decorated' 'data.frame'

See Also

Other conditionalize: conditionalize()

Examples

library(magrittr)
library(dplyr)
library(csv)
file <- system.file(package = 'yamlet', 'extdata','phenobarb.csv')
x <- as.csv(file)
head(x,3)

# suppose we have an event label stored as a column:

x %<>% mutate(evid = ifelse(
  event == 'dose',
  'dose of drug administered',
  'serum phenobarbital concentration'
 )
)

# We can define a conditional label for 'value'
# by mapping evid to event:

x %<>% conditionalize(value, label, event, evid)

x %>% as_yamlet
x %>% write_yamlet


bergsmat/yamlet documentation built on Feb. 18, 2024, 5:50 a.m.