wrapObject: Wrap a data frame to create an object instance

View source: R/wrapObject.R

wrapObjectR Documentation

Wrap a data frame to create an object instance

Description

Wrap a data frame to create an object instance

Usage

wrapObject(df, className, required = NULL, optional = NULL, cleanse = FALSE)

Arguments

df

Data frame to be wrapped (data.frame)

className

Class of new instance (character)

required

Names of required columns, NULL if none (character, optional)

optional

Name of optional columns, NULL if none (character, optional)

cleanse

If TRUE, remove all but the required and optional columns (logical)

Value

The input data frame, converted to a tibble, possibly cleansed of extraneous columns (cleanse = TRUE), and with a class attribute given by className.

Examples

df <- data.frame(Pi = pi, E = exp(1), Foo = "fum")
wrapObject(df, "Numbers")
wrapObject(df, "Numbers", required = c("Pi"), cleanse = TRUE)
wrapObject(df, "Numbers", required = c("Pi"), optional = c("E"))
wrapObject(df, "Numbers", required = c("Pi"), optional = c("E"), cleanse = TRUE)


pteetor/tutils documentation built on March 29, 2025, 6:38 p.m.