tests/testthat/test-df_to_mat.R

test_that("Convert DF to Matrix Frames", {
  expect_equal(
    {
      plate <- well_plate(8, 12)
      set.seed(2)
      df_list <- lapply(1:10, function(x) {
        plate$value <- rnorm(96) * x
        plate$frame <- x
        plate
      })

      df_frames <- do.call(rbind, df_list)

      # convert the data frame to multi-frame matrix
      mat <- well_df_to_mat_frames(
        data = df_frames,
        value = value,
        frame = frame,
        well = well
      )

      tibble::as_tibble(mat[, 1:10])
    },
    {
      tibble::tribble(
        ~A01, ~A02, ~A03, ~A04, ~A05, ~A06, ~A07, ~A08, ~A09, ~A10,
        -0.896914546624981, 0.417650750792556, 2.09081920524915, 0.738938603762125, -0.383586228431444, -0.838287147602044, -1.78824220676485, -0.921275665507737, 0.995984589777751, 1.60039085153952,
        0.184849184646742, 0.981752777463662, -1.19992581964387, 0.318960401097649, -1.95910317516713, 2.06630135573124, 2.03124251875525, 0.330449503465315, -1.69576490337902, 1.68115495576682,
        1.58784533120882, -0.392695355503813, 1.58963820029007, 1.076164353812, -0.841705060135608, -0.562247053342494, -0.703144332993886, -0.141660808936081, -0.533372142547197, -1.18360638822726,
        -1.13037567424629, -1.03966897694891, 1.95465164222325, -0.284157720488246, 1.90354746734764, 1.27571551185092, 0.158164762560122, 0.434847761502698, -1.37226945114308, -1.3584572535632,
        -0.0802517565509893, 1.78222896030858, 0.00493777682814261, -0.776675273979758, 0.622493930120737, -1.04757262699498, 0.50623479748072, -0.053722626017184, -2.20791977880464, -1.512670794721,
        0.132420284381094, -2.31106908460517, -2.45170638784613, -0.595660498691777, 1.99092043558031, -1.96587824144733, -0.819995105616198, -0.907110375593489, 1.82212251875356, -1.2531048993692,
        0.707954729271733, 0.878604580921265, 0.477237302613617, -1.72597977914603, -0.305483724841454, -0.322971093759972, -1.99884699496412, 1.30351223242227, -0.653393410818779, 3.91871415429121,
        -0.23969802417184, 0.035806718015226, -0.596558168631403, -0.902584479763688, -0.0908442352007592, 0.935862526808633, -0.479292591451641, 0.771789775539861, -0.284681219355068, 0.015291744265535,
        1.98447393665293, 1.01282869212708, 0.792203270299649, -0.559061914900466, -0.184161451551261, 1.13922980273408, 0.0841799043222426, 1.05252559530764, -0.386949603644931, -1.68523039517927,
        -0.138787012119665, 0.432265154539617, 0.289636710177348, -0.246512567333516, -1.19876776530741, 1.67161876732599, -0.895486610663309, -1.41003834066371, 0.386694974646073, -1.2023202103047
      )
    }
  )
})
rforbiochemists/wellr documentation built on March 28, 2024, 4:26 a.m.