Skip to contents

This method checks for the presence of columns by name in an annotation_source(). It returns TRUE if all are present, or a vector of messages indicating which columns are missing from the data.frame. It is used by MetMashR to ensure validity of certain objects.

Usage

check_for_columns(obj, ..., msg = FALSE)

Arguments

obj

an annotation_source() object

...

the column names to check for

msg

TRUE/FALSE indicates whether to return a message if some columns are missing. If msg = FALSE then the function returns FALSE if all columns are not present.

Value

logical if all columns are present, or a vector of messages if requested.

Examples

# test if column present
AT <- annotation_source(data.frame(id = character(0)))
#> Error in validObject(obj): invalid class “entity” object: ANY: class of value must match "type"
check_for_columns(AT, "id") # TRUE
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'obj' in selecting a method for function 'check_for_columns': object 'AT' not found
check_for_columns(AT, "cake") # FALSE
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'obj' in selecting a method for function 'check_for_columns': object 'AT' not found

# return a message if missing
check_for_columns(AT, "cake", msg = TRUE)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'obj' in selecting a method for function 'check_for_columns': object 'AT' not found