Skip to contents

Decorates a data.frame. Expects metadata in yamlet format, and loads it onto columns as attributes.

Usage

# S3 method for class 'data.frame'
decorate(
  x,
  meta = NULL,
  ...,
  persistence = getOption("yamlet_persistence", TRUE)
)

Arguments

x

data.frame

meta

file path for corresponding yaml metadata, or a yamlet; an attempt will be made to guess the file path if x has a 'source' attribute

...

passed to decorate.list

persistence

whether to coerce decorated columns to 'dvec' where suitable method exists

Value

class 'decorated' 'data.frame'

Details

As of v0.8.8, the data.frame method for decorate() coerces affected columns using as_dvec if persistence is true and a suitable method exists. 'vctrs' methods are implemented for class dvec to help attributes persist during tidyverse operations. Details are described in c.dvec. Disable this functionality with options(yamlet_persistence = FALSE).

Examples


# find data path
library(csv)
file <- system.file(package = 'yamlet', 'extdata','quinidine.csv')
file
#> [1] "/home/runner/work/_temp/Library/yamlet/extdata/quinidine.csv"
dat <- as.csv(file) # dat now has 'source' attribute

# use source attribute to find metadata 
a <- decorate(as.csv(file))

# supply metadata path (or something close) explicitly
b <- decorate(dat, meta = file)

# these are equivalent
stopifnot(identical(a, b))