From d6054378f0c94c791a7c005f561502d83ef52f1c Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Tue, 24 Sep 2024 19:17:45 -0700 Subject: [PATCH 1/4] adding news --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 41549599..122f3480 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # serocalculator (development version) +* created unit test for `df_to_array()` +* fixed `dplyr::select()` deprecation warning in `df_to_array()` + # serocalculator 1.2.0 * Added `test-summary.pop_data` test From 7a60546f6ca9538af6def8bd1b30234339eb74e1 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Tue, 24 Sep 2024 22:24:06 -0700 Subject: [PATCH 2/4] lint --- R/df_to_array.R | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/R/df_to_array.R b/R/df_to_array.R index c693f5f7..cae62655 100644 --- a/R/df_to_array.R +++ b/R/df_to_array.R @@ -18,10 +18,14 @@ df.to.array <- function( #' Convert a data.frame (or tibble) into a multidimensional array #' -#' @param df a [data.frame()] (or [tibble::tibble()]) in long format (each row contains one value for the intended array) -#' @param dim_var_names a [character()] vector of variable names in `df`. All of these variables should be factors, or a warning will be produced. -#' @param value_var_name a [character()] variable containing a variable name from `df` which contains the values for the intended array. -#' @return an [array()] with dimensions defined by the variables in `df` listed in `dim_var_names` +#' @param df a [data.frame()] (or [tibble::tibble()]) in long format +#' (each row contains one value for the intended array) +#' @param dim_var_names a [character()] vector of variable names in `df`. +#' All of these variables should be factors, or a warning will be produced. +#' @param value_var_name a [character()] variable containing a variable name +#' from `df` which contains the values for the intended array. +#' @return an [array()] with dimensions defined by the variables in `df` +#' listed in `dim_var_names` #' #' @examples #' library(dplyr) @@ -33,7 +37,9 @@ df.to.array <- function( #' cols = c("Sepal.Length", "Sepal.Width", "Petal.Width", "Petal.Length") #' ) %>% #' mutate(parameter = factor(parameter, levels = unique(parameter))) -#' arr <- df %>% serocalculator:::df_to_array(dim_var_names = c("parameter", "Species")) +#' arr <- df %>% +#' serocalculator:::df_to_array( +#' dim_var_names = c("parameter", "Species")) #' ftable(arr[,,1:5]) #' @noRd df_to_array <- function( @@ -77,6 +83,6 @@ df_to_array <- function( ) df %>% - mutate(.by = all_of(dim_var_names), obs = 1:n()) %>% + mutate(.by = all_of(dim_var_names), obs = row_number()) %>% xtabs(formula = formula(xtabs_formula)) } From bd5b1f9f0d17e666f2e800186fd2d0d5344d8795 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Tue, 24 Sep 2024 22:25:18 -0700 Subject: [PATCH 3/4] lint --- tests/testthat/test-df_to_array.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-df_to_array.R b/tests/testthat/test-df_to_array.R index b081c588..5cff9937 100644 --- a/tests/testthat/test-df_to_array.R +++ b/tests/testthat/test-df_to_array.R @@ -4,9 +4,15 @@ test_that("df_to_array() produces consistent results", { df <- iris %>% tidyr::pivot_longer( names_to = "parameter", - cols = c("Sepal.Length", "Sepal.Width", "Petal.Width", "Petal.Length") + cols = c( + "Sepal.Length", + "Sepal.Width", + "Petal.Width", + "Petal.Length" + ) ) %>% mutate(parameter = factor(parameter, levels = unique(parameter))) - arr <- df %>% serocalculator:::df_to_array(dim_var_names = c("parameter", "Species")) + arr <- df %>% serocalculator:::df_to_array( + dim_var_names = c("parameter", "Species")) arr %>% expect_snapshot_value(style = "serialize") }) From 0b247fe7620b5add1fcc6772507d2060647ef784 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Tue, 24 Sep 2024 23:15:11 -0700 Subject: [PATCH 4/4] exclude deprecated function name from name linter --- R/df_to_array.R | 2 +- tests/testthat/test-df_to_array.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/df_to_array.R b/R/df_to_array.R index cae62655..c772d054 100644 --- a/R/df_to_array.R +++ b/R/df_to_array.R @@ -8,7 +8,7 @@ #' #' @keywords internal #' -df.to.array <- function( +df.to.array <- function( # nolint: object_name_linter df, dim_var_names, value_var_name = "value") { diff --git a/tests/testthat/test-df_to_array.R b/tests/testthat/test-df_to_array.R index 5cff9937..39b760aa 100644 --- a/tests/testthat/test-df_to_array.R +++ b/tests/testthat/test-df_to_array.R @@ -12,7 +12,7 @@ test_that("df_to_array() produces consistent results", { ) ) %>% mutate(parameter = factor(parameter, levels = unique(parameter))) - arr <- df %>% serocalculator:::df_to_array( - dim_var_names = c("parameter", "Species")) + arr <- df %>% + serocalculator:::df_to_array(dim_var_names = c("parameter", "Species")) arr %>% expect_snapshot_value(style = "serialize") })