Skip to content

Commit

Permalink
implemented passing unstructured data during tomic_to coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
shackett committed Apr 22, 2024
1 parent f4f6530 commit b0cce69
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions R/data_classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,11 @@ triple_to_tidy <- function(triple_omic) {
output$data <- tidy_output
output$design <- triple_omic$design

if ("unstructured" %in% names(triple_omic)) {
# copy unstructured data as-is
output$unstructured <- triple_omic$unstructured
}

class(output) <- c("tidy_omic", "tomic", class(triple_omic)[3])

output
Expand Down Expand Up @@ -691,6 +696,11 @@ tidy_to_triple <- function(tidy_omic) {
design = tidy_omic$design
)

if ("unstructured" %in% names(tidy_omic)) {
# copy unstructured data as-is
output$unstructured <- tidy_omic$unstructured
}

class(output) <- c("triple_omic", "tomic", class(tidy_omic)[3])

output
Expand Down
4 changes: 3 additions & 1 deletion R/dim_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ impute_missing_values <- function(
tomic,
impute_var_name = "imputed",
value_var = NULL,
...) {
...
){

if (!("impute" %in% rownames(utils::installed.packages()))) {
stop("Install \"impute\" using remotes::install_bioc(\"impute\") to use this function")
}
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-data_classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ test_that("Create triple omic", {
sample_pk = "sample_id"
)

testthat::expect_s3_class(simple_triple, "triple_omic")
})

test_that("Unstructured data preserved using tomic_to", {

triple_omic <- tomic_to(simple_triple, "triple_omic")
triple_omic$unstructured$dat <- "test"

tidy_copy <- triple_to_tidy(triple_omic)
expect_equal(tidy_copy$unstructured$dat, "test")

triple_restore <- tidy_to_triple(tidy_copy)
expect_equal(triple_restore$unstructured$dat, "test")
})


Expand Down

0 comments on commit b0cce69

Please sign in to comment.