This function adds metadata variables from a given data frame to an object, aligning the data with existing observations.

addMetaDataObs(
  object,
  meta_obs_df,
  var_names = NULL,
  na_warn = TRUE,
  overwrite = FALSE
)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

meta_obs_df

A data frame containing new metadata variables to be added. This data frame must contain a column named barcodes which is used as the key for merging. Other columns should represent the metadata variables to be added.

var_names

A character vector specifying which columns from meta_obs_df should be added as metadata variables. If NULL, all columns except barcodes and sample will be added. Default is NULL.

na_warn

Logical value indicating whether to issue warnings if NAs are introduced in the new metadata variables. Default is TRUE.

overwrite

Logical value. Must be TRUE to allow overwriting.

Value

The updated input object, containing the added, removed or computed results.

Details

The input meta_obs_df must satisfy the following requirements:

  • It must be a data frame.

  • It must contain a column named barcodes, which will be used as the key for merging the metadata variables with the existing observations.

  • Any other columns can represent the metadata variables to be added. These columns must not be named "barcodes" or "sample".

  • The columns specified in var_names must be present in meta_obs_df.

The function checks for the existence of the specified metadata variables in the object. If overwrite is FALSE, it ensures that no existing variables are overwritten. If NAs are introduced in the new metadata variables, warnings will be issued if na_warn is TRUE.