Skip to content

Commit

Permalink
used coerce_to_class to convert imputation features and samples back …
Browse files Browse the repository at this point in the history
…to their input classes
  • Loading branch information
shackett committed Apr 22, 2024
1 parent b0cce69 commit 4548b0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions R/dim_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ impute_missing_values <- function(
) %>%
dplyr::as_tibble()

# coerce feature and/or sample variables to their original classes
# (they will be converted to characters by impute.knn)

imputed_measurements[[feature_pk]] <- coerce_to_classes(
imputed_measurements[[feature_pk]],
triple_omic$features[[feature_pk]]
)

imputed_measurements[[sample_pk]] <- coerce_to_classes(
imputed_measurements[[sample_pk]],
triple_omic$samples[[sample_pk]]
)

# if in-place imputation is desired then remove the old variable
updated_measurements <- triple_omic$measurements
if (value_var == impute_var_name) {
updated_measurements <- updated_measurements %>%
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-dim_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ test_that("Removing missing values works", {
expect_equal(nrow(filtered_brauer$samples), 34)
expect_equal(nrow(filtered_brauer$measurements), 15674)
})

test_that("Matrices keys are reconstructed with appropriate classes", {

tomic_with_missing_values <- simple_triple
tomic_with_missing_values$measurements <- tomic_with_missing_values$measurements %>%
dplyr::slice(-c(1:5))

if (!("impute" %in% rownames(utils::installed.packages()))) {
cli::cli_alert("{.pkg impute} is not available for testing; imputation tests will be skipped")
} else{
imputed_tomic <- impute_missing_values(tomic_with_missing_values)
expect_s3_class(imputed_tomic, "triple_omic")
}


})

0 comments on commit 4548b0f

Please sign in to comment.