R/uids.R

Defines functions uids.t_ext_solutions_df uids.t_solutions_df uids.solutions_df uids.sim_mats_list uids.ext_solutions_df uids.default uids.data_list uids

Documented in uids

#' Pull UIDs from an object
#'
#' @param x The object to extract UIDs from.
#' @return A character vector of UIDs.
#' @export
uids <- function(x) {
    UseMethod("uids")
}

#' @export
uids.data_list <- function(x) {
    uid_vec <- attributes(x)$"uids"
    return(uid_vec)
}

#' @export
uids.default <- function(x) {
    uid_vec <- attributes(x)$"uids"
    if (is.null(uid_vec)) {
        metasnf_warning(
            "No UIDs in object of type: ", class(x)[[1]], "\n"
        )
    } else {
        return(uid_vec)
    }
}

#' @export
uids.ext_solutions_df <- function(x) {
    uid_vec <- colnames(x)[grepl("^uid_", colnames(x))]
    return(uid_vec)
}

#' @export
uids.sim_mats_list <- function(x) {
    if (length(x) >= 1) {
        uid_vec <- colnames(x[[1]])
        return(uid_vec)
    } else {
        metasnf_warning(
            "No UIDs in empty `sim_mats_list`."
        )
    }
}

#' @export
uids.solutions_df <- function(x) {
    uid_vec <- colnames(x)[grepl("^uid_", colnames(x))]
    return(uid_vec)
}

#' @export
uids.t_solutions_df <- function(x) {
    return(x$"uid")
}

#' @export
uids.t_ext_solutions_df <- function(x) {
    uids(t(x))
}

Try the metasnf package in your browser

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

metasnf documentation built on June 8, 2025, 12:47 p.m.