R/get-dataset-by-id.R

Defines functions get_dataset_by_id

Documented in get_dataset_by_id

#' Get the dataset by id (a string).  annot_samples can be used at the top level
#' to share sample annotations among other datasets.
#'
#' @param dataset_id a string, either 'dataset.name' or just 'name'
#'
#' @return the dataset element
#'
#' @export
get_dataset_by_id <- function(dataset_id) {
    if (!is.character(dataset_id)) {
        stop(paste0("dataset_id should be a string, not ", class(dataset_id)))
    }

    dataset <- NULL

    if (exists(dataset_id)) {
        dataset <- get(dataset_id)
    } else {
        expanded <- sprintf("dataset.%s", dataset_id)
        if (exists(expanded)) {
            dataset <- get(expanded)
        }
    }

    if (invalid(dataset)) {
        stop(sprintf("'%s' does not exist", dataset_id))
    }

    return(dataset)
}
churchill-lab/qtl2api documentation built on April 17, 2025, 3:27 a.m.