R/trim_dataset.R

Defines functions trim_dataset

#' Internal function to trim input data for `mx_dataset()`
#'
#' @inheritParams mx_dataset
#'
#' @return subset of data input to `mx_dataset()` (data.frame)
#' @noRd
trim_dataset <- function(data,
                          slide_id,
                          image_id,
                          marker_cols,
                          metadata_cols = NULL){
    if(!is.null(metadata_cols)){
        if(!all(c(slide_id,image_id,marker_cols,metadata_cols) %in% colnames(data))){
            stop(
                "All column identifiers must be in the dataset",
                call. = FALSE
            )
        }
        return(data[,c(slide_id,image_id,marker_cols,metadata_cols)])
    }


    if(!all(c(slide_id,image_id,marker_cols) %in% colnames(data))){
        stop(
            "All column identifiers must be in the dataset",
            call. = FALSE
        )
    }
    data[,c(slide_id,image_id,marker_cols)]
}

Try the mxnorm package in your browser

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

mxnorm documentation built on May 1, 2023, 5:20 p.m.