R/add_column.R

#' @include AllGenerics.R AllClasses.R
NULL

#' @describeIn add_column Add a column to any slot
#' @export
setMethod("add_column",
    signature = signature(
        object = "TidySet",
        slot = "character",
        columns = "ANY"
    ),
    function(object, slot, columns) {
        slot <- match.arg(slot, c("sets", "elements", "relations"))
        original <- slot(object, slot)

        if (nrow(columns) != nrow(original)) {
            stop("Please columns should be of the same size as the slot",
                call. = FALSE
            )
        }
        out <- cbind(original, columns)
        slot(object, slot) <- out
        validObject(object)
        object
    }
)

Try the BaseSet package in your browser

Any scripts or data that you put into this service are public.

BaseSet documentation built on Aug. 22, 2023, 5:11 p.m.