From daa259692eaac5a1e96c269ada9513a61fc1528b Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Thu, 4 May 2023 11:56:55 -0400 Subject: [PATCH 01/16] Add Zenodo badge. --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index eb8e591..ddd9181 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,7 @@ title: "Release notes for `matsindf`" output: html_document --- -# matsindf 0.4.2 (2023-05-04) +# matsindf 0.4.2 (2023-05-04) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7896799.svg)](https://doi.org/10.5281/zenodo.7896799) * Move to latest version of GitHub test coverage workflow. * This version not released to CRAN. From 11beea68c7ce8c96bcfe1c76c8b3692a864e4630 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 16 May 2023 15:32:43 -0400 Subject: [PATCH 02/16] matrix.class --> matrix_class --- NEWS.md | 2 +- R/collapse.R | 8 ++++---- R/utilities.R | 8 ++++---- man/collapse_to_matrices.Rd | 4 ++-- man/rowcolval_to_mat.Rd | 4 ++-- tests/testthat/test-collapse.R | 22 +++++++++++----------- tests/testthat/test-expand.R | 2 +- tests/testthat/test-utilities.R | 18 +++++++++--------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/NEWS.md b/NEWS.md index ddd9181..165abf8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -49,7 +49,7 @@ output: html_document as appropriate. * `mat_to_rowcolval()` now accepts `Matrix` objects in the `.matrix` argument. -* `rowcolval_to_mat()` gains a `matrix.class` argument +* `rowcolval_to_mat()` gains a `matrix_class` argument that specifies whether a `matrix` or a `Matrix` should be created. * Many new tests to verify that the package works with `Matrix` objects. diff --git a/R/collapse.R b/R/collapse.R index f35e4d6..be8eeec 100644 --- a/R/collapse.R +++ b/R/collapse.R @@ -57,7 +57,7 @@ #' @param coltypes An optional string identifying the column in `.DF` containing the type of values in columns of the matrices to be created #' Default is `if ("coltypes" %in% names(.DF)) "rowtypes" else NULL`, #' so that failure to set the coltypes argument will give `NULL`, as appropriate. -#' @param matrix.class The type of matrix to be created, one of "matrix" or "Matrix". +#' @param matrix_class The type of matrix to be created, one of "matrix" or "Matrix". #' Default is "matrix". #' #' @return A data frame with matrices in the `matvals` column. @@ -96,8 +96,8 @@ collapse_to_matrices <- function(.DF, matnames = "matnames", matvals = "matvals", rownames = "rownames", colnames = "colnames", rowtypes = if ("rowtypes" %in% names(.DF)) "rowtypes" else NULL, coltypes = if ("coltypes" %in% names(.DF)) "coltypes" else NULL, - matrix.class = c("matrix", "Matrix")) { - matrix.class <- match.arg(matrix.class) + matrix_class = c("matrix", "Matrix")) { + matrix_class <- match.arg(matrix_class) # Ensure that none of rownames, colnames, or values is a group variable. # These can't be in the group variables. # If they were, we wouldn't be able to summarise them into the matrices. @@ -130,7 +130,7 @@ collapse_to_matrices <- function(.DF, matnames = "matnames", matvals = "matvals" # Convert .DF to matrices "{matvals}" := rowcolval_to_mat(.data, rownames = rownames, colnames = colnames, matvals = matvals, rowtypes = rowtypes, coltypes = coltypes, - matrix.class = matrix.class) + matrix_class = matrix_class) ) %>% dplyr::select(!!!dplyr::group_vars(.DF), !!matvals) %>% data.frame(check.names = FALSE) diff --git a/R/utilities.R b/R/utilities.R index a0e99ab..50fc749 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -101,7 +101,7 @@ mat_to_rowcolval <- function(.matrix, matvals = "matvals", #' @param rowtypes An optional string identifying the types of information found in rows of the matrix to be constructed. Default is "rowtypes". #' @param coltypes An optional string identifying the types of information found in columns of the matrix to be constructed. Default is "coltypes". #' @param fill The value for missing entries in the resulting matrix. default is `0`. -#' @param matrix.class The type of matrix to be created, one of "matrix" or "Matrix". +#' @param matrix_class The type of matrix to be created, one of "matrix" or "Matrix". #' Default is "matrix". #' #' @return A matrix with named rows and columns and, optionally, row and column types. @@ -142,8 +142,8 @@ mat_to_rowcolval <- function(.matrix, matvals = "matvals", rowcolval_to_mat <- function(.DF, matvals = "matvals", rownames = "rownames", colnames = "colnames", rowtypes = "rowtypes", coltypes = "coltypes", - fill = 0, matrix.class = c("matrix", "Matrix")){ - matrix.class <- match.arg(matrix.class) + fill = 0, matrix_class = c("matrix", "Matrix")){ + matrix_class <- match.arg(matrix_class) if (!is.null(rowtypes)) { # If rowtype is supplied and is not NA, check if it is one of the columns of .DF if (rowtypes %in% colnames(.DF)) { @@ -206,7 +206,7 @@ rowcolval_to_mat <- function(.DF, matvals = "matvals", tibble::column_to_rownames(var = rownames) %>% as.matrix() %>% matsbyname::setrowtype(rowtype = rowtypes) %>% matsbyname::setcoltype(coltype = coltypes) - if (matrix.class == "Matrix") { + if (matrix_class == "Matrix") { out <- matsbyname::Matrix(out) } return(out) diff --git a/man/collapse_to_matrices.Rd b/man/collapse_to_matrices.Rd index 912f6c2..61cb17e 100644 --- a/man/collapse_to_matrices.Rd +++ b/man/collapse_to_matrices.Rd @@ -12,7 +12,7 @@ collapse_to_matrices( colnames = "colnames", rowtypes = if ("rowtypes" \%in\% names(.DF)) "rowtypes" else NULL, coltypes = if ("coltypes" \%in\% names(.DF)) "coltypes" else NULL, - matrix.class = c("matrix", "Matrix") + matrix_class = c("matrix", "Matrix") ) } \arguments{ @@ -40,7 +40,7 @@ so that failure to set the rowtypes argument will give \code{NULL}, as appropria Default is \code{if ("coltypes" \%in\% names(.DF)) "rowtypes" else NULL}, so that failure to set the coltypes argument will give \code{NULL}, as appropriate.} -\item{matrix.class}{The type of matrix to be created, one of "matrix" or "Matrix". +\item{matrix_class}{The type of matrix to be created, one of "matrix" or "Matrix". Default is "matrix".} } \value{ diff --git a/man/rowcolval_to_mat.Rd b/man/rowcolval_to_mat.Rd index ebb67d3..909296a 100644 --- a/man/rowcolval_to_mat.Rd +++ b/man/rowcolval_to_mat.Rd @@ -12,7 +12,7 @@ rowcolval_to_mat( rowtypes = "rowtypes", coltypes = "coltypes", fill = 0, - matrix.class = c("matrix", "Matrix") + matrix_class = c("matrix", "Matrix") ) } \arguments{ @@ -30,7 +30,7 @@ rowcolval_to_mat( \item{fill}{The value for missing entries in the resulting matrix. default is \code{0}.} -\item{matrix.class}{The type of matrix to be created, one of "matrix" or "Matrix". +\item{matrix_class}{The type of matrix to be created, one of "matrix" or "Matrix". Default is "matrix".} } \value{ diff --git a/tests/testthat/test-collapse.R b/tests/testthat/test-collapse.R index b75f53b..807c224 100644 --- a/tests/testthat/test-collapse.R +++ b/tests/testthat/test-collapse.R @@ -91,28 +91,28 @@ test_that("small example works with Matrix objects", { matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = "rowtypes", coltypes = "coltypes", - matrix.class = "Matrix"), + matrix_class = "Matrix"), "row is/are grouping variable/s. Cannot group on rownames, colnames, rowtypes, coltypes, or matvals in argument .DF of collapse_to_matrices.") # Try with NULL rowtypes but non-NULL coltypes and expect an error. expect_error(collapse_to_matrices(tidy %>% dplyr::group_by(matrix), matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = NULL, coltypes = "coltypes", - matrix.class = "Matrix"), + matrix_class = "Matrix"), "One of rowtypes or coltypes was non-NULL while the other was NULL. Both need to be NULL or both need to be non-NULL in collapse_to_matrices.") # Try with NULL coltypes but non-NULL rowtypes and expect an error. expect_error(collapse_to_matrices(tidy %>% dplyr::group_by(matrix), matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = "rowtypes", coltypes = NULL, - matrix.class = "Matrix"), + matrix_class = "Matrix"), "One of rowtypes or coltypes was non-NULL while the other was NULL. Both need to be NULL or both need to be non-NULL in collapse_to_matrices.") # Group on the right things and expect success. mats <- collapse_to_matrices(tidy %>% dplyr::group_by(matrix), matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = "rowtypes", coltypes = "coltypes", - matrix.class = "Matrix") + matrix_class = "Matrix") # Check that groups are discarded. expect_equal(length(dplyr::group_vars(mats)), 0) # Check that factors are not created for String columns. @@ -150,7 +150,7 @@ test_that("small example works with Matrix objects", { matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = NULL, coltypes = NULL, - matrix.class = "Matrix") + matrix_class = "Matrix") # Test for V1 expect_equal(mats_trimmed$vals[[1]], matsbyname::Matrix(c(1, 2, 0, 3), nrow = 2, ncol = 2, byrow = TRUE, dimnames = list(c("i1", "i2"), c("p1", "p2")))) @@ -226,7 +226,7 @@ test_that("collapse_to_matrices() works with Matrix objects", { mats <- collapse_to_matrices(tidy, matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = "rowtypes", coltypes = "coltypes", - matrix.class = "Matrix") + matrix_class = "Matrix") A <- matsbyname::Matrix(c(11, 0, 0, 22), nrow = 2, ncol = 2, byrow = TRUE, @@ -299,7 +299,7 @@ test_that("collapse_to_matrices() works correctly when row and col types are NUL matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = NULL, coltypes = NULL, - matrix.class = "Matrix") + matrix_class = "Matrix") expect_null(mats$vals[[1]] %>% matsbyname::rowtype()) expect_null(mats$vals[[1]] %>% matsbyname::coltype()) @@ -310,7 +310,7 @@ test_that("collapse_to_matrices() works correctly when row and col types are NUL mats2 <- collapse_to_matrices(tidy %>% dplyr::group_by(matrix), matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_null(mats2$vals[[1]] %>% matsbyname::rowtype()) expect_null(mats2$vals[[1]] %>% matsbyname::coltype()) @@ -353,7 +353,7 @@ test_that("new defaults for rowtypes and coltypes arguments work with Matrix obj # They should default to NULL. mats <- collapse_to_matrices(tidy, matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", - matrix.class = "Matrix") %>% + matrix_class = "Matrix") %>% tidyr::pivot_wider(names_from = matrix, values_from = vals) expect_null(mats$U[[1]] |> matsbyname::rowtype()) expect_null(mats$U[[2]] |> matsbyname::rowtype()) @@ -392,7 +392,7 @@ test_that("collapse_to_matrices() works with various matnames arguments and Matr # Try wtih NULL mats <- collapse_to_matrices(tidy, matnames = NULL, matvals = "vals", rownames = "row", colnames = "col", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_equal(mats$vals[[1]], matsbyname::Matrix(c(1, 2, 0, 3), byrow = TRUE, nrow = 2, ncol = 2, @@ -400,7 +400,7 @@ test_that("collapse_to_matrices() works with various matnames arguments and Matr # Try with unspecified mats2 <- collapse_to_matrices(tidy, matvals = "vals", rownames = "row", colnames = "col", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_equal(mats2$vals[[1]], matsbyname::Matrix(c(1, 2, 0, 3), byrow = TRUE, nrow = 2, ncol = 2, diff --git a/tests/testthat/test-expand.R b/tests/testthat/test-expand.R index d3ccb45..81815f3 100644 --- a/tests/testthat/test-expand.R +++ b/tests/testthat/test-expand.R @@ -105,7 +105,7 @@ test_that("expand_to_tidy() works with Matrix objects", { mats <- collapse_to_matrices(tidy, matnames = "matrix", rownames = "row", colnames = "col", rowtypes = "rowtypes", coltypes = "coltypes", matvals = "vals", - matrix.class = "Matrix") %>% + matrix_class = "Matrix") %>% dplyr::ungroup() # For the first tests, do not drop 0 values. A <- expand_to_tidy(mats, matnames = "matrix", matvals = "vals", diff --git a/tests/testthat/test-utilities.R b/tests/testthat/test-utilities.R index c147315..3b37ed1 100644 --- a/tests/testthat/test-utilities.R +++ b/tests/testthat/test-utilities.R @@ -166,7 +166,7 @@ test_that("rowcolval_to_mat() (collapse) works with Matrix objects", { vals = c( 11 , 12, 22 ), stringsAsFactors = FALSE) A <- rowcolval_to_mat(rowcolval, rownames = "rows", colnames = "cols", matvals = "vals", - rowtypes = NULL, coltypes = NULL, matrix.class = "Matrix") + rowtypes = NULL, coltypes = NULL, matrix_class = "Matrix") expect_true(inherits(A, "Matrix")) expect_equal(A, expected_mat) expect_null(matsbyname::rowtype(A)) # rowtype has not been set @@ -175,7 +175,7 @@ test_that("rowcolval_to_mat() (collapse) works with Matrix objects", { # Provide single row and column types to be applied to all entries. B <- rowcolval_to_mat(rowcolval, rownames = "rows", colnames = "cols", matvals = "vals", rowtypes = "Products", coltypes = "Industries", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_true(matsbyname::is.Matrix(B)) expect_equal(B, expected_mat_with_types) @@ -186,7 +186,7 @@ test_that("rowcolval_to_mat() (collapse) works with Matrix objects", { stringsAsFactors = FALSE)) %>% rowcolval_to_mat(rownames = "rows", colnames = "cols", matvals = "vals", rowtypes = "rt", coltypes = "ct", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_equal(C, expected_mat_with_types) # Also works for single values if both the rownames and colnames columns contain NA @@ -196,14 +196,14 @@ test_that("rowcolval_to_mat() (collapse) works with Matrix objects", { D <- rowcolval2 %>% rowcolval_to_mat(rownames = "rows", colnames = "cols", matvals = "vals", rowtypes = "rowtype", coltypes = "coltype", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_equal(D, 2) # Try without rowtype or coltype columns in the data frame. rowcolval3 <- data.frame(Country = c("GH"), rows = c(NA), cols = c(NA), vals = c(2), stringsAsFactors = FALSE) E <- rowcolval3 %>% rowcolval_to_mat(rownames = "rows", colnames = "cols", matvals = "vals", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_equal(E, 2) # Fails when rowtype or coltype not all same. In rowcolval4, column rt is not all same. @@ -215,7 +215,7 @@ test_that("rowcolval_to_mat() (collapse) works with Matrix objects", { rownames = "rows", colnames = "cols", matvals = "vals", rowtypes = "rt", coltypes = "ct", - matrix.class = "Matrix"), + matrix_class = "Matrix"), "Not all values in rt \\(rowtype\\) were same as first entry: Products") rowcolval5 <- rowcolval %>% dplyr::bind_cols(data.frame(rt = c("Products", "Products", "Products"), @@ -225,7 +225,7 @@ test_that("rowcolval_to_mat() (collapse) works with Matrix objects", { rownames = "rows", colnames = "cols", matvals = "vals", rowtypes = "rt", coltypes = "ct", - matrix.class = "Matrix"), + matrix_class = "Matrix"), "Not all values in ct \\(coltype\\) were same as first entry: Industries") }) @@ -257,7 +257,7 @@ test_that("mat_to_rowcolval() (expand) works with Matrix objects", { A <- data %>% rowcolval_to_mat(rownames = "rows", colnames = "cols", rowtypes = "rt", coltypes = "ct", matvals = "vals", - matrix.class = "Matrix") + matrix_class = "Matrix") expect_true(matsbyname::is.Matrix(A)) expect_equal(A, expected_mat) @@ -507,7 +507,7 @@ test_that("matrix_cols() works with Matrix objects", { collapse_to_matrices(matnames = "matrix", matvals = "vals", rownames = "row", colnames = "col", rowtypes = "rowtypes", coltypes = "coltypes", - matrix.class = "Matrix") %>% + matrix_class = "Matrix") %>% dplyr::mutate( integer = 42, string = "hello world" From f9ae65e0bc568c8e98eadf9f438fdac849d317d7 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 16 May 2023 15:33:26 -0400 Subject: [PATCH 03/16] Better NEWS.md. --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index 165abf8..2153db8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,11 @@ title: "Release notes for `matsindf`" output: html_document --- + +* renamed `matrix.class` argument to `matrix_class`. + + + # matsindf 0.4.2 (2023-05-04) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7896799.svg)](https://doi.org/10.5281/zenodo.7896799) * Move to latest version of GitHub test coverage workflow. From c4dfcebb64edfbebc1c33a0648b19a1d55687e5f Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 16 May 2023 15:33:48 -0400 Subject: [PATCH 04/16] Better NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2153db8..2f8ced2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ output: html_document --- -* renamed `matrix.class` argument to `matrix_class`. +* Renamed `matrix.class` argument to `matrix_class`. From 2953c3e61dccaa392ee7b3e6d766a4d58ffb9daa Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 16 May 2023 16:02:35 -0400 Subject: [PATCH 05/16] Correctly identify matrix.class when it was introduced. --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2f8ced2..404c6f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -54,7 +54,7 @@ output: html_document as appropriate. * `mat_to_rowcolval()` now accepts `Matrix` objects in the `.matrix` argument. -* `rowcolval_to_mat()` gains a `matrix_class` argument +* `rowcolval_to_mat()` gains a `matrix.class` argument that specifies whether a `matrix` or a `Matrix` should be created. * Many new tests to verify that the package works with `Matrix` objects. From d1147c94f8c9bf41dffb7c018948f53193403544 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Thu, 18 May 2023 21:21:58 -0400 Subject: [PATCH 06/16] working on deprecation warnings. --- DESCRIPTION | 1 + R/collapse.R | 17 +++++++++++++++-- man/collapse_to_matrices.Rd | 8 +++++++- tests/testthat/test-collapse.R | 13 ++++++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 854f6de..f1001fd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,6 +19,7 @@ Depends: R (>= 2.10) Imports: assertthat, dplyr, + lifecycle, magrittr, matsbyname, purrr, diff --git a/R/collapse.R b/R/collapse.R index be8eeec..d7fdf9a 100644 --- a/R/collapse.R +++ b/R/collapse.R @@ -57,8 +57,12 @@ #' @param coltypes An optional string identifying the column in `.DF` containing the type of values in columns of the matrices to be created #' Default is `if ("coltypes" %in% names(.DF)) "rowtypes" else NULL`, #' so that failure to set the coltypes argument will give `NULL`, as appropriate. -#' @param matrix_class The type of matrix to be created, one of "matrix" or "Matrix". -#' Default is "matrix". +#' @param matrix.class `r lifecycle::badge("deprecated")` Use `matrix_class` instead. +#' @param matrix_class One of "matrix" or "Matrix". +#' "matrix" creates a `base::matrix` object with the `matrix()` function. +#' "Matrix" creates a `Matrix::Matrix` object using the `matsbyname::Matrix()` function. +#' This could be a sparse matrix. +#' Default is "matrix". #' #' @return A data frame with matrices in the `matvals` column. #' @@ -96,8 +100,17 @@ collapse_to_matrices <- function(.DF, matnames = "matnames", matvals = "matvals", rownames = "rownames", colnames = "colnames", rowtypes = if ("rowtypes" %in% names(.DF)) "rowtypes" else NULL, coltypes = if ("coltypes" %in% names(.DF)) "coltypes" else NULL, + matrix.class = lifecycle::deprecated(), matrix_class = c("matrix", "Matrix")) { + if (lifecycle::is_present(matrix.class)) { + lifecycle::deprecate_warn(when = "0.6.3", + what = "create_matrix_byname(matrix.class)", + with = "create_matrix_byname(matrix_class)") + matrix_class <- matrix.class + } + matrix_class <- match.arg(matrix_class) + # Ensure that none of rownames, colnames, or values is a group variable. # These can't be in the group variables. # If they were, we wouldn't be able to summarise them into the matrices. diff --git a/man/collapse_to_matrices.Rd b/man/collapse_to_matrices.Rd index 61cb17e..e50cf6c 100644 --- a/man/collapse_to_matrices.Rd +++ b/man/collapse_to_matrices.Rd @@ -12,6 +12,7 @@ collapse_to_matrices( colnames = "colnames", rowtypes = if ("rowtypes" \%in\% names(.DF)) "rowtypes" else NULL, coltypes = if ("coltypes" \%in\% names(.DF)) "coltypes" else NULL, + matrix.class = lifecycle::deprecated(), matrix_class = c("matrix", "Matrix") ) } @@ -40,7 +41,12 @@ so that failure to set the rowtypes argument will give \code{NULL}, as appropria Default is \code{if ("coltypes" \%in\% names(.DF)) "rowtypes" else NULL}, so that failure to set the coltypes argument will give \code{NULL}, as appropriate.} -\item{matrix_class}{The type of matrix to be created, one of "matrix" or "Matrix". +\item{matrix.class}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{matrix_class} instead.} + +\item{matrix_class}{One of "matrix" or "Matrix". +"matrix" creates a \code{base::matrix} object with the \code{matrix()} function. +"Matrix" creates a \code{Matrix::Matrix} object using the \code{matsbyname::Matrix()} function. +This could be a sparse matrix. Default is "matrix".} } \value{ diff --git a/tests/testthat/test-collapse.R b/tests/testthat/test-collapse.R index 807c224..41e390a 100644 --- a/tests/testthat/test-collapse.R +++ b/tests/testthat/test-collapse.R @@ -389,7 +389,7 @@ test_that("collapse_to_matrices() works with various matnames arguments and Matr col = c("p1", "p2", "p2"), vals = c(1, 2, 3)) - # Try wtih NULL + # Try with NULL mats <- collapse_to_matrices(tidy, matnames = NULL, matvals = "vals", rownames = "row", colnames = "col", matrix_class = "Matrix") @@ -406,3 +406,14 @@ test_that("collapse_to_matrices() works with various matnames arguments and Matr 0, 3), byrow = TRUE, nrow = 2, ncol = 2, dimnames = list(c("i1", "i2"), c("p1", "p2")))) }) + + +test_that("collapse_to_matrices() deprecation is correct", { + tidy <- tibble::tibble(row = c("i1", "i1", "i2"), + col = c("p1", "p2", "p2"), + vals = c(1, 2, 3)) + + expect_warning(collapse_to_matrices(tidy, matnames = NULL, + matvals = "vals", rownames = "row", colnames = "col", + matrix.class = "matrix")) +}) From 5669a180a312eb2cf4184ca0fe64250d54010eeb Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Thu, 18 May 2023 21:22:43 -0400 Subject: [PATCH 07/16] Better NEWS.md --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 404c6f7..07e77c2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,10 +4,11 @@ output: html_document --- +* Deprecated `matrix.class` argument. + It will be removed soon. * Renamed `matrix.class` argument to `matrix_class`. - # matsindf 0.4.2 (2023-05-04) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7896799.svg)](https://doi.org/10.5281/zenodo.7896799) * Move to latest version of GitHub test coverage workflow. From ea5ea1180e8f3c6d55c7fe79b7afa6c889fcf2d1 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Thu, 18 May 2023 21:27:52 -0400 Subject: [PATCH 08/16] More deprecations. --- R/utilities.R | 18 ++++++++++++++++-- man/rowcolval_to_mat.Rd | 8 +++++++- tests/testthat/test-utilities.R | 12 ++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index 50fc749..e536212 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -101,7 +101,11 @@ mat_to_rowcolval <- function(.matrix, matvals = "matvals", #' @param rowtypes An optional string identifying the types of information found in rows of the matrix to be constructed. Default is "rowtypes". #' @param coltypes An optional string identifying the types of information found in columns of the matrix to be constructed. Default is "coltypes". #' @param fill The value for missing entries in the resulting matrix. default is `0`. -#' @param matrix_class The type of matrix to be created, one of "matrix" or "Matrix". +#' @param matrix.class `r lifecycle::badge("deprecated")` Use `matrix_class` instead. +#' @param matrix_class One of "matrix" or "Matrix". +#' "matrix" creates a `base::matrix` object with the `matrix()` function. +#' "Matrix" creates a `Matrix::Matrix` object using the `matsbyname::Matrix()` function. +#' This could be a sparse matrix. #' Default is "matrix". #' #' @return A matrix with named rows and columns and, optionally, row and column types. @@ -142,8 +146,18 @@ mat_to_rowcolval <- function(.matrix, matvals = "matvals", rowcolval_to_mat <- function(.DF, matvals = "matvals", rownames = "rownames", colnames = "colnames", rowtypes = "rowtypes", coltypes = "coltypes", - fill = 0, matrix_class = c("matrix", "Matrix")){ + fill = 0, + matrix.class = lifecycle::deprecated(), + matrix_class = c("matrix", "Matrix")) { + if (lifecycle::is_present(matrix.class)) { + lifecycle::deprecate_warn(when = "0.6.3", + what = "create_matrix_byname(matrix.class)", + with = "create_matrix_byname(matrix_class)") + matrix_class <- matrix.class + } + matrix_class <- match.arg(matrix_class) + if (!is.null(rowtypes)) { # If rowtype is supplied and is not NA, check if it is one of the columns of .DF if (rowtypes %in% colnames(.DF)) { diff --git a/man/rowcolval_to_mat.Rd b/man/rowcolval_to_mat.Rd index 909296a..425873d 100644 --- a/man/rowcolval_to_mat.Rd +++ b/man/rowcolval_to_mat.Rd @@ -12,6 +12,7 @@ rowcolval_to_mat( rowtypes = "rowtypes", coltypes = "coltypes", fill = 0, + matrix.class = lifecycle::deprecated(), matrix_class = c("matrix", "Matrix") ) } @@ -30,7 +31,12 @@ rowcolval_to_mat( \item{fill}{The value for missing entries in the resulting matrix. default is \code{0}.} -\item{matrix_class}{The type of matrix to be created, one of "matrix" or "Matrix". +\item{matrix.class}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{matrix_class} instead.} + +\item{matrix_class}{One of "matrix" or "Matrix". +"matrix" creates a \code{base::matrix} object with the \code{matrix()} function. +"Matrix" creates a \code{Matrix::Matrix} object using the \code{matsbyname::Matrix()} function. +This could be a sparse matrix. Default is "matrix".} } \value{ diff --git a/tests/testthat/test-utilities.R b/tests/testthat/test-utilities.R index 3b37ed1..4882d55 100644 --- a/tests/testthat/test-utilities.R +++ b/tests/testthat/test-utilities.R @@ -230,6 +230,18 @@ test_that("rowcolval_to_mat() (collapse) works with Matrix objects", { }) +test_that("rowcolval_to_mat() deprecation works as expected", { + rowcolval <- data.frame(Country = c("GH", "GH", "GH"), + rows = c( "p1", "p1", "p2"), + cols = c( "i1", "i2", "i2"), + vals = c( 11 , 12, 22 ), + stringsAsFactors = FALSE) + expect_warning(rowcolval_to_mat(rowcolval, rownames = "rows", colnames = "cols", matvals = "vals", + rowtypes = NULL, coltypes = NULL, + matrix.class = "matrix")) +}) + + test_that("mat_to_rowcolval() (expand) works with Matrix objects", { # This is the matrix we expect to obtain. expected_mat <- matsbyname::Matrix(c(11, 12, From 0b20e91b0dfded0846dedac5a76b89ee2f84041e Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Mon, 22 May 2023 14:29:59 -0400 Subject: [PATCH 09/16] Prep for release. --- R/collapse.R | 2 +- R/utilities.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/collapse.R b/R/collapse.R index d7fdf9a..35f05f0 100644 --- a/R/collapse.R +++ b/R/collapse.R @@ -103,7 +103,7 @@ collapse_to_matrices <- function(.DF, matnames = "matnames", matvals = "matvals" matrix.class = lifecycle::deprecated(), matrix_class = c("matrix", "Matrix")) { if (lifecycle::is_present(matrix.class)) { - lifecycle::deprecate_warn(when = "0.6.3", + lifecycle::deprecate_warn(when = "0.4.3", what = "create_matrix_byname(matrix.class)", with = "create_matrix_byname(matrix_class)") matrix_class <- matrix.class diff --git a/R/utilities.R b/R/utilities.R index e536212..eb08930 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -150,7 +150,7 @@ rowcolval_to_mat <- function(.DF, matvals = "matvals", matrix.class = lifecycle::deprecated(), matrix_class = c("matrix", "Matrix")) { if (lifecycle::is_present(matrix.class)) { - lifecycle::deprecate_warn(when = "0.6.3", + lifecycle::deprecate_warn(when = "0.4.3", what = "create_matrix_byname(matrix.class)", with = "create_matrix_byname(matrix_class)") matrix_class <- matrix.class From a9561fa37a93bbdc1426b8963c54ef3b8810684b Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Mon, 22 May 2023 14:32:04 -0400 Subject: [PATCH 10/16] new website --- docs/articles/matsindf.html | 2 +- docs/articles/midf_apply_primer.html | 2 +- docs/news/index.html | 3 ++- docs/pkgdown.yml | 2 +- docs/reference/collapse_to_matrices.html | 12 ++++++++++-- docs/reference/rowcolval_to_mat.html | 12 ++++++++++-- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/docs/articles/matsindf.html b/docs/articles/matsindf.html index 9c87d20..011c19f 100644 --- a/docs/articles/matsindf.html +++ b/docs/articles/matsindf.html @@ -79,7 +79,7 @@

Matthew Kuperus Heun

-

2023-05-04

+

2023-05-22

Source: vignettes/matsindf.Rmd
matsindf.Rmd
diff --git a/docs/articles/midf_apply_primer.html b/docs/articles/midf_apply_primer.html index 4f3f6e5..43ecd1f 100644 --- a/docs/articles/midf_apply_primer.html +++ b/docs/articles/midf_apply_primer.html @@ -79,7 +79,7 @@

Matthew Kuperus Heun

-

2023-05-04

+

2023-05-22

Source: vignettes/midf_apply_primer.Rmd
midf_apply_primer.Rmd
diff --git a/docs/news/index.html b/docs/news/index.html index a95bd65..1dff04b 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -55,7 +55,8 @@
-

matsindf 0.4.2 (2023-05-04)

+

matsindf 0.4.2 (2023-05-04) DOI +

  • Move to latest version of GitHub test coverage workflow.
  • This version not released to CRAN.
  • No new tests. diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 56ec9ec..544d133 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,5 +5,5 @@ articles: iris_pca: iris_pca.html matsindf: matsindf.html midf_apply_primer: midf_apply_primer.html -last_built: 2023-05-04T15:50Z +last_built: 2023-05-22T18:30Z diff --git a/docs/reference/collapse_to_matrices.html b/docs/reference/collapse_to_matrices.html index 9e57d1b..1cdc6e9 100644 --- a/docs/reference/collapse_to_matrices.html +++ b/docs/reference/collapse_to_matrices.html @@ -159,7 +159,8 @@

    Usage colnames = "colnames", rowtypes = if ("rowtypes" %in% names(.DF)) "rowtypes" else NULL, coltypes = if ("coltypes" %in% names(.DF)) "coltypes" else NULL, - matrix.class = c("matrix", "Matrix") + matrix.class = lifecycle::deprecated(), + matrix_class = c("matrix", "Matrix") )

@@ -204,7 +205,14 @@

Arguments

[Deprecated] Use matrix_class instead.

+ + +
matrix_class
+

One of "matrix" or "Matrix". +"matrix" creates a base::matrix object with the matrix() function. +"Matrix" creates a Matrix::Matrix object using the matsbyname::Matrix() function. +This could be a sparse matrix. Default is "matrix".

diff --git a/docs/reference/rowcolval_to_mat.html b/docs/reference/rowcolval_to_mat.html index f6ef908..3b67fe6 100644 --- a/docs/reference/rowcolval_to_mat.html +++ b/docs/reference/rowcolval_to_mat.html @@ -90,7 +90,8 @@

Usage rowtypes = "rowtypes", coltypes = "coltypes", fill = 0, - matrix.class = c("matrix", "Matrix") + matrix.class = lifecycle::deprecated(), + matrix_class = c("matrix", "Matrix") ) @@ -125,7 +126,14 @@

Arguments

[Deprecated] Use matrix_class instead.

+ + +
matrix_class
+

One of "matrix" or "Matrix". +"matrix" creates a base::matrix object with the matrix() function. +"Matrix" creates a Matrix::Matrix object using the matsbyname::Matrix() function. +This could be a sparse matrix. Default is "matrix".

From 4cce4b6f8039aac7a39e9cc8f817d7339e11fdba Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Mon, 22 May 2023 14:32:58 -0400 Subject: [PATCH 11/16] Better NEWS.md --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 07e77c2..4d7da65 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,9 @@ output: html_document * Deprecated `matrix.class` argument. It will be removed soon. * Renamed `matrix.class` argument to `matrix_class`. +* New tests for deprecations. + * Now at 376 tests, all passing. + * Test coverage remains at 100 %. # matsindf 0.4.2 (2023-05-04) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7896799.svg)](https://doi.org/10.5281/zenodo.7896799) From 6413180d8a98ea1d148a056dd4fdcbf102528286 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 23 May 2023 15:03:57 -0400 Subject: [PATCH 12/16] Testing on rhub etc. --- cran-comments.md | 35 ----------------------------------- inst/WORDLIST | 1 + 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index 66eba9a..9972d5f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -14,60 +14,29 @@ See `NEWS.md` for details. * notes: 0 * GitHub Actions: * macOS-latest (release) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 * ubuntu-latest (devel) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 * ubuntu-latest (release) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 * ubuntu-latest (oldrel-1) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 * windows-latest (release) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 * Windows (on win-builder): * `devtools::check_win_release()`, R version 4.3.0 (2023-04-21 ucrt) * ERRORs: 0 * WARNINGs: 0 * NOTEs: 0 * `devtools::check_win_oldrelease()`, R version 4.2.3 (2023-03-15 ucrt) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 * `devtools::check_win_devel()` R Under development (unstable) (2023-04-25 r84327 ucrt) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 * rhub: * `devtools::check_rhub()` - * Windows Server 2022, R-devel, 64 bit - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 1 - checking for detritus in the temp directory ... NOTE - Found the following files/directories: - 'lastMiKTeXException' - This note appears to be a minor problem with the cleanup process, not caused by the `matsindf` package itself. * `devtools::check_rhub()` * Ubuntu Linux 20.04.1 LTS, R-release, GCC - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 1 - checking HTML version of manual ... NOTE - Skipping checking HTML validation: no command 'tidy' found - This NOTE appears to be an anomaly, as it occurs only on rhub. * Fedora Linux, R-devel, clang, gfortran - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 1 - checking HTML version of manual ... NOTE - Skipping checking HTML validation: no command 'tidy' found - This NOTE appears to be an anomaly, as it occurs only on rhub. @@ -75,8 +44,4 @@ See `NEWS.md` for details. ## revdepcheck results -We checked 1 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. - * We saw 0 new problems - * We failed to check 0 packages - diff --git a/inst/WORDLIST b/inst/WORDLIST index 88e7248..cc49db5 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -9,6 +9,7 @@ Codecov coltypes colvec dat +deprecations doi dplyr ECC From eafbe33f3ed6b52e3e2f24146bef9af73b686b81 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 23 May 2023 15:34:52 -0400 Subject: [PATCH 13/16] Better CRAN comments. --- cran-comments.md | 56 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index 9972d5f..ea13feb 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,42 +1,77 @@ ## Context -`matsindf` v0.4.1 includes a rewrite of `matsindf_apply()` -to make it easier to debug and maintain. +`matsindf` v0.4.3 includes a rewrite of `matsindf_apply()`, +making it easier to debug and maintain. Better error messages are now available, too. +Finally, the latest version of the GitHub test coverage workflow +is now being used. See `NEWS.md` for details. ## Test environments (12 in total) and R CMD check results -* local: macOS X 13.3.1 (Ventura), R4.3.0 +* local: macOS X 13.3.1(a) (Ventura), R4.3.0 * errors: 0 * warnings: 0 * notes: 0 * GitHub Actions: * macOS-latest (release) + * errors: 0 + * warnings: 0 + * notes: 0 * ubuntu-latest (devel) + * errors: 0 + * warnings: 0 + * notes: 0 * ubuntu-latest (release) + * errors: 0 + * warnings: 0 + * notes: 0 * ubuntu-latest (oldrel-1) + * errors: 0 + * warnings: 0 + * notes: 0 * windows-latest (release) + * errors: 0 + * warnings: 0 + * notes: 0 * Windows (on win-builder): * `devtools::check_win_release()`, R version 4.3.0 (2023-04-21 ucrt) - * ERRORs: 0 - * WARNINGs: 0 - * NOTEs: 0 + * errors: 0 + * warnings: 0 + * notes: 0 * `devtools::check_win_oldrelease()`, R version 4.2.3 (2023-03-15 ucrt) - * `devtools::check_win_devel()` R Under development (unstable) (2023-04-25 r84327 ucrt) + * errors: 0 + * warnings: 0 + * notes: 0 + * `devtools::check_win_devel()` R Under development (unstable) (2023-05-19 r84451 ucrt) + * errors: 0 + * warnings: 0 + * notes: 0 * rhub: * `devtools::check_rhub()` + * Windows Server 2022, R-devel, 64 bit + * errors: 0 + * warnings: 0 + * notes: 2 + - checking for non-standard things in the check directory ... NOTE + - Found the following files/directories: + - ''NULL'' - checking for detritus in the temp directory ... NOTE - Found the following files/directories: - 'lastMiKTeXException' - - This note appears to be a minor problem with the cleanup process, not caused by the `matsindf` package itself. - * `devtools::check_rhub()` + - These notes appear to be minor problems with the cleanup process, not caused by the `matsindf` package itself. * Ubuntu Linux 20.04.1 LTS, R-release, GCC + * errors: 0 + * warnings: 0 + * notes: 1 - checking HTML version of manual ... NOTE - Skipping checking HTML validation: no command 'tidy' found - This NOTE appears to be an anomaly, as it occurs only on rhub. * Fedora Linux, R-devel, clang, gfortran + * errors: 0 + * warnings: 0 + * notes: 1 - checking HTML version of manual ... NOTE - Skipping checking HTML validation: no command 'tidy' found - This NOTE appears to be an anomaly, as it occurs only on rhub. @@ -44,4 +79,7 @@ See `NEWS.md` for details. ## revdepcheck results +We checked 1 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. + * We saw 0 new problems + * We failed to check 0 packages From b6ac8ba60728b705082ef647b0e42a50e9ce7245 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 23 May 2023 15:37:06 -0400 Subject: [PATCH 14/16] Prep for release. --- DESCRIPTION | 4 ++-- NEWS.md | 2 ++ inst/CITATION | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f1001fd..a237cbb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: matsindf Type: Package Title: Matrices in Data Frames -Version: 0.4.2 -Date: 2023-05-04 +Version: 0.4.3 +Date: 2023-05-23 Authors@R: c(person("Matthew", "Heun", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7438-214X"), email = "matthew.heun@me.com")) diff --git a/NEWS.md b/NEWS.md index 4d7da65..67197d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ output: html_document --- +# matsindf 0.4.3 (2023-05-23) + * Deprecated `matrix.class` argument. It will be removed soon. * Renamed `matrix.class` argument to `matrix_class`. diff --git a/inst/CITATION b/inst/CITATION index 855d321..03386fe 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -8,10 +8,10 @@ bibentry( role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7438-214X")), year = "2023", - note = "R package version 0.4.2", + note = "R package version 0.4.3", url = "https://CRAN.R-project.org/package=matsindf", textVersion = paste("Matthew Kuperus Heun (2023).", "matsindf: Matrices in Data Frames", - "R package version 0.4.2", + "R package version 0.4.3", "https://CRAN.R-project.org/package=matsindf") ) From 34d8dc8370dc882ca653f25e3833056f5d6907a3 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 23 May 2023 15:39:06 -0400 Subject: [PATCH 15/16] New version of website. --- docs/404.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/articles/matsindf.html | 4 ++-- docs/articles/midf_apply_primer.html | 4 ++-- docs/authors.html | 6 +++--- docs/index.html | 2 +- docs/news/index.html | 11 ++++++++++- docs/pkgdown.yml | 2 +- docs/reference/UKEnergy2000.html | 2 +- docs/reference/add_UKEnergy2000_matnames.html | 2 +- docs/reference/add_UKEnergy2000_row_col_meta.html | 2 +- docs/reference/collapse_to_matrices.html | 2 +- docs/reference/data.html | 2 +- docs/reference/df_to_msg.html | 2 +- docs/reference/everything_except.html | 2 +- docs/reference/expand_to_tidy.html | 2 +- docs/reference/group_by_everything_except.html | 2 +- docs/reference/index.html | 2 +- docs/reference/index_column.html | 2 +- docs/reference/mat_to_rowcolval.html | 2 +- docs/reference/matsindf_apply.html | 2 +- docs/reference/matsindf_apply_types.html | 2 +- docs/reference/pipe.html | 2 +- docs/reference/quasi-quote-assign.html | 2 +- docs/reference/rowcolval_to_mat.html | 2 +- docs/reference/verify_cols_missing.html | 2 +- 27 files changed, 40 insertions(+), 31 deletions(-) diff --git a/docs/404.html b/docs/404.html index a3cc14e..e0ecf06 100644 --- a/docs/404.html +++ b/docs/404.html @@ -24,7 +24,7 @@ matsindf - 0.4.2 + 0.4.3