Skip to content

Commit

Permalink
fix (qp_dilute): always return data.frame
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiAragaki committed May 6, 2024
1 parent 8c9620c commit 2358275
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ make_pipette_vol <- function(x) {
#' @param quiet Logical. If FALSE, will warn when dilution is impossible to do
#' without concentrating sample.
#'
#' @return a named list, with `sample_to_add` as the volume of sample to add,
#' @return a data.frame, with `sample_to_add` as the volume of sample to add,
#' and `add_to` as the volume to dilute the sample into.
#'
#' @examples
Expand All @@ -52,6 +52,6 @@ dilute <- function(c1,
v1 <- (c2 * v2) / c1
x <- data.frame(sample_to_add = v1, add_to = v2 - v1)
if (round_for_pipettes)
x <- apply(x, 2, make_pipette_vol)
x
x <- apply(x, 2, make_pipette_vol, simplify = FALSE)
as.data.frame(x)
}
12 changes: 8 additions & 4 deletions tests/testthat/test-qp_dilute.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})

test_that("length_is_recyclable works", {
expect_true(length_is_recyclable(1, iris[1, ]))
expect_true(length_is_recyclable(1, iris[1:2, ]))
Expand Down Expand Up @@ -36,3 +32,11 @@ test_that("NULL target_conc uses lowest concentration", {
expect_equal(out$sample_to_add, c(6, 3, 2, 1.5))
expect_equal(out$add_to, c(-4, -1, 0, 0.5))
})

test_that("output type same regardless of input len", {
short <- data.frame(.pred_conc = 1) |>
qp_dilute(target_conc = 1, target_vol = 2)
long <- data.frame(.pred_conc = c(1, 2)) |>
qp_dilute(target_conc = 1, target_vol = 2)
expect_equal(class(short), class(long))
})

0 comments on commit 2358275

Please sign in to comment.