Automatically handles name collisions by appending versioned suffixes:

  • No collision -> petPC1, petPC2, ...

  • Collision -> petPCr01.1, petPCr01.2, ...

  • Next round -> petPCr02.1, petPCr02.2, ...

apply_simlr_matrices(
  existing_df,
  simlr_v,
  n_limit = NULL,
  version_prefix = "r",
  verbose = FALSE
)

Arguments

existing_df

Data frame (samples in rows, features in columns)

simlr_v

Named list of weight matrices (rownames = original features)

n_limit

Optional: keep only first n_limit components per block

version_prefix

Prefix before version number (default: "r")

verbose

Print messages when versioning occurs

Value

List with extended_df and new_colnames

Examples

set.seed(123)
df <- data.frame(petPC1 = rnorm(5), petPC2 = rnorm(5), age = 1:5)
W <- matrix(rnorm(6), 2, 3,
            dimnames = list(c("petPC1", "petPC2"), c("PC1", "PC2", "PC3")))
weights <- list(pet = W)

# First application
res1 <- apply_simlr_matrices(df, weights, verbose = TRUE)
#> petPC1 -> petPCr00.1
#> petPC2 -> petPCr00.2
res1$new_colnames
#> [1] "petPCr00.1" "petPCr00.2" "petPC3"    
# [1] "petPCr01.1" "petPCr01.2" "petPCr01.3"

# Second application
res2 <- apply_simlr_matrices(res1$extended_df, weights)
res2$new_colnames
#> [1] "petPCr01.1" "petPCr01.2" "petPCr00.3"
# [1] "petPCr02.1" "petPCr02.2" "petPCr02.3"

# No collision example
clean <- df[, "age", drop = FALSE]
apply_simlr_matrices(clean, weights)$new_colnames
#> Warning: No overlapping features for block 'pet' - skipping
#> Warning: No projections were added
#> character(0)
# [1] "petPC1" "petPC2" "petPC3"