ys_prune: Prune a data frame, keeping columns in a yspec object

View source: R/class-yspec.R

ys_pruneR Documentation

Prune a data frame, keeping columns in a yspec object

Description

Use this to scavenge a data frame for columns that you want to keep. Select additional columns through .... Do not use this for final column selection; use dplyr::select() instead.

Usage

ys_prune(data, spec, ..., .report = FALSE)

Arguments

data

A data frame with at least one column that is found in spec.

spec

A yspec object.

...

Additional columns carry into the output, specified using tidy-select syntax.

.report

If TRUE, report missing columns.

Details

An error is generated if there are no columns in common between data and spec.

Value

A data frame with common columns with spec and ..., in the order they appear in spec.

Examples

data <- ys_help$data()
spec <- ys_help$spec()
data$STUDY <- NULL

head(ys_prune(data, spec))
head(ys_prune(data, spec, .report = TRUE))

data$FOO <- 1
data$BAR <- 2
data$YAK <- 3

head(ys_prune(data, spec, YAK, FOO))

# Use this for final subsetting
# It will fail if all the columns aren't there
data <- ys_help$data()
head(dplyr::select(data, names(spec)))
 

metrumresearchgroup/yspec documentation built on Dec. 22, 2024, 1:37 a.m.