has_multiple_levels: Variable has multiple levels?

View source: R/1_assertions.R

has_multiple_levelsR Documentation

Variable has multiple levels?

Description

Variable has multiple levels?

Usage

has_multiple_levels(x, ...)

## S3 method for class 'character'
has_multiple_levels(x, .xname = get_name_in_parent(x), ...)

## S3 method for class 'factor'
has_multiple_levels(x, .xname = get_name_in_parent(x), ...)

## S3 method for class 'numeric'
has_multiple_levels(x, .xname = get_name_in_parent(x), ...)

## S3 method for class 'data.table'
has_multiple_levels(
  x,
  y,
  .xname = get_name_in_parent(x),
  .yname = get_name_in_parent(y),
  ...
)

## S3 method for class 'SummarizedExperiment'
has_multiple_levels(
  x,
  y,
  .xname = get_name_in_parent(x),
  .yname = get_name_in_parent(y),
  ...
)

Arguments

x

vector, data.table or SummarizedExperiment

...

required for s3 dispatch

.xname

string

y

string

.yname

string

Value

TRUE or false

Examples

# numeric
    a <- numeric();                               has_multiple_levels(a)
    a <- c(1, 1);                                 has_multiple_levels(a)
    a <- c(1, 2);                                 has_multiple_levels(a)
# character
    a <- character();                             has_multiple_levels(a)
    a <- c('A', 'A');                             has_multiple_levels(a)
    a <- c('A', 'B');                             has_multiple_levels(a)
# factor
    a <- factor();                                has_multiple_levels(a)
    a <- factor(c('A', 'A'));                     has_multiple_levels(a)
    a <- factor(c('A', 'B'));                     has_multiple_levels(a)
# data.table
    dt <- data.table(a = factor());               has_multiple_levels(dt, 'b')
    dt <- data.table(a = factor());               has_multiple_levels(dt, 'a')
    dt <- data.table(a = factor());               has_multiple_levels(dt, 'a')
    dt <- data.table(a = factor(c('A', 'A')));    has_multiple_levels(dt, 'a')
    dt <- data.table(a = factor(c('A', 'B')));    has_multiple_levels(dt, 'a')
# sumexp
    object <- matrix(1:9, nrow = 3)
    rownames(object) <- sprintf('f%d', 1:3)
    colnames(object) <- sprintf('s%d', 1:3)
    object <- list(exprs = object)
    object %<>% SummarizedExperiment::SummarizedExperiment()
    object$subgroup <- c('A', 'A', 'A');          has_multiple_levels(object, 'group')
    object$subgroup <- c('A', 'A', 'A');          has_multiple_levels(object, 'subgroup')
    object$subgroup <- c('A', 'B', 'A');          has_multiple_levels(object, 'subgroup')

bhagwataditya/importomics documentation built on July 11, 2024, 11:26 a.m.