PolyGenius
Contents

roles

Inspect role metadata carried by a PolyGeniusFrame

roles() reads the named role mapping stored on a fetched PolyGeniusFrame. Roles are metadata: they hold column names, so use ordinary data-frame access (frame[[...]], frame[, ..., drop = FALSE]) to reach the values themselves.

roles(x) <- value replaces the whole role mapping on a PolyGeniusFrame, roles(x, "outcomes") <- "y" replaces one named role, and roles(x, c("outcomes", "predictors")) <- list(...) replaces several at once.

Usage

roles(x, role = NULL, ...)

roles(x, role = NULL) <- value

S3 method for class 'PolyGeniusFrame'

roles(x, role = NULL, ...)

Default S3 method:

roles(x, role = NULL, ...)

S3 method for class 'PolyGeniusFrame'

roles(x, role = NULL) <- value

Default S3 method:

roles(x, role = NULL) <- value

Arguments

ArgumentDescription
xA PolyGeniusFrame.
roleCharacter scalar, character vector, or NULL (default). Role names to return; NULL returns the whole mapping. A non-character role aborts.
...Unused. Present for S3 method compatibility.
valueReplacement mapping: a character vector for a single role, a named list for role = NULL or for several roles, or an unnamed list the same length as role.

Value

  • With role = NULL, a named list of every role mapping (list() when none is set).
  • With a length-one role, a character vector of that role's column names.
  • With a longer role, a named list of character vectors, one per requested name.

x, with its groups attribute updated. The input is not modified.

Details

A requested role the frame does not carry comes back as character(), not an error. On any class other than PolyGeniusFrame the default method aborts.

Every replacement value must be a character vector naming columns present on the frame; duplicates are dropped and NULL means the empty role. Assignment aborts when a full replacement is not a named list, when a value names a column the frame does not have, when several roles are replaced with an unnamed list of the wrong length, or when the names supplied do not match the roles requested. On any class other than PolyGeniusFrame the default method aborts.

Examples

frame <- study$fetch(age, sex, outcome(dementia))
roles(frame)
roles(frame, "outcomes")

See Also

Aliases: roles, roles<-, roles.PolyGeniusFrame, roles.default, roles<-.PolyGeniusFrame, roles<-.default