Skip to content

Commit

Permalink
version 0.3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHeun authored and cran-robot committed Jan 24, 2023
1 parent 5eb9931 commit bb095f8
Show file tree
Hide file tree
Showing 24 changed files with 1,039 additions and 591 deletions.
13 changes: 7 additions & 6 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: matsindf
Type: Package
Title: Matrices in Data Frames
Version: 0.3.11
Date: 2022-05-18
Version: 0.3.12
Date: 2023-01-24
Authors@R: c(person("Matthew", "Heun", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7438-214X"),
email = "matthew.heun@me.com"))
Expand All @@ -13,16 +13,17 @@ License: MIT + file LICENSE
Language: en-US
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.0
RoxygenNote: 7.2.3
Depends: R (>= 2.10)
Imports: dplyr, magrittr, matsbyname, purrr, rlang, tibble, tidyr
Suggests: covr, ggplot2, knitr, RCLabels, rmarkdown, spelling, testthat
Suggests: covr, ggplot2, Hmisc, knitr, RCLabels, rmarkdown, spelling,
testthat
Config/testthat/edition: 3
VignetteBuilder: knitr
URL: https://github.com/MatthewHeun/matsindf
BugReports: https://github.com/MatthewHeun/matsindf/issues
NeedsCompilation: no
Packaged: 2022-05-19 12:59:12 UTC; mkh2
Packaged: 2023-01-25 00:38:27 UTC; mkh2
Author: Matthew Heun [aut, cre] (<https://orcid.org/0000-0002-7438-214X>)
Repository: CRAN
Date/Publication: 2022-05-19 13:20:02 UTC
Date/Publication: 2023-01-25 00:50:02 UTC
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,2 +1,2 @@
YEAR: 2022
YEAR: 2023
COPYRIGHT HOLDER: Matthew Kuperus Heun
44 changes: 23 additions & 21 deletions MD5
@@ -1,41 +1,43 @@
e1f8b8a7e300af9d5174cfeb9ca4b08b *DESCRIPTION
48e44876707d63eece2c5fab64cacc15 *LICENSE
f5f590c72b11ab746d662a42727417b3 *NAMESPACE
0081dd30bf93b0d6a542f52957eab2d9 *NEWS.md
a707ca2714d1f79c4ae0a1d3e502453c *DESCRIPTION
58a3c955cbbf973ec3fa1898f9e9f182 *LICENSE
28b9fb61cd668f96027d296d08b07abe *NAMESPACE
5705756632dc569e404b70a0fda53ff1 *NEWS.md
07e9619c519a4555d0a4a52136b3a8af *R/collapse.R
f74acdac92135210d2e51daef4ced235 *R/data.R
ae790120a1a44da5ecf8edc103431e71 *R/expand.R
a8e3195897bacb52262d27c79c2a09b8 *R/matsindf_apply.R
0874367810191d5713392bc88b013e8a *R/utilities.R
ec2122278b8840558f1d32429d82a142 *R/data.R
a22f6793a7b7c34108398b3f49594f87 *R/expand.R
65eebad2f68a8a2f1e8369bddc33b4e1 *R/matsindf_apply.R
eca78db419b8201f5a376de0a4efaaa2 *R/utilities.R
e3702e4a4f1c2f263d84afd1e53f185c *R/utils-.data.R
15355d49503b97b502d614bc1629aefa *R/utils-pipe.R
f60225411bc1570c427e39238dc2c8c2 *R/utils-qqassign.R
726ddac0a53e1e024268749c46bfac6b *README.md
c890661466bd8fa92bb33d2c36151a0b *build/vignette.rds
ea124a494ad7922985532ad3b308e4d5 *build/partial.rdb
279b6b78f5c7609ee3fa088380de4a00 *build/vignette.rds
8e890f45eea6929749a53f5c49db8d80 *data/UKEnergy2000.rda
06c79f69992005e37714c0c77a442982 *inst/CITATION
bd8e0c6b229111b7c532d7c207ad6701 *inst/CITATION
bc4d88a62b30136b4db89d349c3ac396 *inst/WORDLIST
e68b3aaaf76912751f8dff77ac754326 *inst/doc/iris_pca.R
7cd37ad63ba95504eccda7762e1ba3aa *inst/doc/iris_pca.Rmd
b3e634067ec4d2304ad503382402149d *inst/doc/iris_pca.html
9468b310de57408a302178eb31772e68 *inst/doc/iris_pca.html
49c938acbb5aa316f8b3d78573af8734 *inst/doc/matsindf.R
afd9f781834457ab22880f3419c62ae4 *inst/doc/matsindf.Rmd
77582428f47974e460131ce9f51e4226 *inst/doc/matsindf.html
8ed0d1531ae5d19e5d96b7c473399420 *inst/doc/midf_apply_primer.R
ac0b476766474c602d64844285480e37 *inst/doc/midf_apply_primer.Rmd
67751efc546bde2ef8ee4ae82d84ff8c *inst/doc/midf_apply_primer.html
e7bd260e3ef68ee779c92ac4ea8b867d *man/UKEnergy2000.Rd
69176531f72e3dcacc9b52b8ac00555a *inst/doc/matsindf.html
485fa2e100721d78d02763d5db32d154 *inst/doc/midf_apply_primer.R
b2e3da673708123eebe738cd4a5fa379 *inst/doc/midf_apply_primer.Rmd
25a99c7a3649dfa4bd6a012b2f0b0f87 *inst/doc/midf_apply_primer.html
24627d4f6f4d8d302fa5b0d163cb023c *man/UKEnergy2000.Rd
9efef69d4592fa064023ef08607fcf94 *man/add_UKEnergy2000_matnames.Rd
2b3b543bfe8cbc20a65a4b37c6c342c4 *man/add_UKEnergy2000_row_col_meta.Rd
89b69e680d097b46e2b587de60577eaa *man/collapse_to_matrices.Rd
32ec27f8d295593fe3d4d72927cf5962 *man/data.Rd
5824b74cd7d0bd21716c8d2a8aa1193f *man/df_to_msg.Rd
466f54c2ff4cae8f69997e68ea65dc77 *man/everything_except.Rd
d48d44a6dc7782e4780ff0eca6d77be6 *man/expand_to_tidy.Rd
9b02c4132344dd24627411f33e52c0a6 *man/expand_to_tidy.Rd
b2dd8fc6eb10f8e500a78b6c2069c9ec *man/group_by_everything_except.Rd
96892d1c7cb1a49f69f3084ef5aa4d40 *man/index_column.Rd
983d0d1a850b6a90cfba14d0e0c5c31d *man/mat_to_rowcolval.Rd
2102151a6f5c240da89a880907d3e54b *man/matsindf_apply.Rd
10fbcac0fcce590c2b95453a75690c33 *man/matrix_cols.Rd
ea163df2c8746cd6071a8cf4433bd9ba *man/matsindf_apply.Rd
c5e90a4c39cb6d36ab5f597d3ff8c1b4 *man/matsindf_apply_types.Rd
6eef5d2f49de0f38fd4bee2a0eadb799 *man/pipe.Rd
c1f1088e8dc4f7b59661dd74d293beef *man/quasi-quote-assign.Rd
Expand All @@ -47,9 +49,9 @@ a9eecca1fd9f4078e4ed9a64830cdf17 *tests/testthat/UKEnergy2000_with_UVY.rds
fa505a94f1c22afbe56b6fbde33a5d5b *tests/testthat/UKEnergy2000_with_metadata.rds
e2f5768a703d1cf79cd64400d7850839 *tests/testthat/test-collapse.R
f1fb327f810b6f5f52729cd2f08101f4 *tests/testthat/test-expand.R
c79de4cea3122ec5b090a586ccc3fb5f *tests/testthat/test-matsindf_apply.R
ad710b2e110594a89c34b31974c7b40a *tests/testthat/test-utilities.R
932f2af864394496841d80f0c773795d *tests/testthat/test-matsindf_apply.R
0b0568ed52cb53937aad770f28dfed9b *tests/testthat/test-utilities.R
41d243a4d4106763cb78f7924490c205 *vignettes/References.bib
7cd37ad63ba95504eccda7762e1ba3aa *vignettes/iris_pca.Rmd
afd9f781834457ab22880f3419c62ae4 *vignettes/matsindf.Rmd
ac0b476766474c602d64844285480e37 *vignettes/midf_apply_primer.Rmd
b2e3da673708123eebe738cd4a5fa379 *vignettes/midf_apply_primer.Rmd
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -10,6 +10,7 @@ export(expand_to_tidy)
export(group_by_everything_except)
export(index_column)
export(mat_to_rowcolval)
export(matrix_cols)
export(matsindf_apply)
export(matsindf_apply_types)
export(rowcolval_to_mat)
Expand Down
34 changes: 28 additions & 6 deletions NEWS.md
Expand Up @@ -4,7 +4,26 @@ output: html_document
---


# matsindf 0.3.11 (2022-05-18)
# matsindf 0.3.12 (2023-01-24)

* Fixed a differential error message challenge for tests.
* Move tests associated with `verify_cols_missing()`
from the `Recca` package to `matsindf`.
Those tests didn't belong in `Recca`.
* Updated to the latest version of the github actions
continuous integration workflow.
* Better docs for `expand_to_tidy()`.
* New function `matrix_cols()` tells which columns contain matrices,
either in the `any()` sense or in the `all()` sense.
* Improved `matsindf_apply()` primer vignette
discusses how to handle heterogeneous arguments
types to `FUN`.
* New tests to verify `matsindf_apply()` when using string arguments to `FUN`.
* Now at 209 tests, all passing.
* Test coverage remains at 100 %.


# matsindf 0.3.11 (2022-05-18) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6564300.svg)](https://doi.org/10.5281/zenodo.6564300)

* Fixed a very subtle bug in `matsindf_apply()` where the list returned from `Map()`
had names on each individual item.
Expand All @@ -15,9 +34,12 @@ output: html_document
The solution was to remove the names from each individual item
after calling `Map()` and
before calling `purrr::transpose()`.
* No new tests.
* Still at 195 tests, all passing.
* Test coverage remains at 100 %.


# matsindf 0.3.10 (2020-12-17) [![DOI](https://zenodo.org/badge/112986384.svg)](https://zenodo.org/badge/latestdoi/112986384)
# matsindf 0.3.10 (2021-12-17) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5789218.svg)](https://doi.org/10.5281/zenodo.5789218)

* New vignette from Alexander Davis shows how to use `matsindf`
for principal components analysis (PCA).
Expand All @@ -33,7 +55,7 @@ output: html_document
* Test coverage remains at 100 %.


# matsindf 0.3.9 (2020-10-02) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5546359.svg)](https://doi.org/10.5281/zenodo.5546359)
# matsindf 0.3.9 (2021-10-02) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5546359.svg)](https://doi.org/10.5281/zenodo.5546359)

* New function `df_to_msg()` can assist with error messages.
`df_to_msg()` was moved from the `SEAPSUTWorkflow` package,
Expand All @@ -43,7 +65,7 @@ output: html_document
* Test coverage remains at 100 %.


# matsindf 0.3.8 (2020-09-02) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5475444.svg)](https://doi.org/10.5281/zenodo.5475444)
# matsindf 0.3.8 (2021-09-02) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5475444.svg)](https://doi.org/10.5281/zenodo.5475444)

* `matsindf.Rmd` vignette now uses the `keep` argument on `matsbyname::hatize_byname()`.
* Fixed a bug in the `matsindf.Rmd` vignette.
Expand All @@ -54,7 +76,7 @@ output: html_document
* Test coverage remains at 100 %.


# matsindf 0.3.7 (2020-04-11)
# matsindf 0.3.7 (2021-04-11)

* Not released to CRAN, because there are no changes in the code itself.
* Move away from Travis to GitHub Actions for continuous integration testing.
Expand All @@ -71,7 +93,7 @@ output: html_document

# matsindf 0.3.6 (2020-08-24)

* To comply with a deprecating change in `dplyr`,
* To comply with a breaking change in `dplyr`,
all calls to `dplyr::group_by()` now use `.add` argument
instead of `add` argument.

Expand Down
14 changes: 6 additions & 8 deletions R/data.R
Expand Up @@ -3,14 +3,12 @@
#' A dataset containing approximations to
#' some of the energy flows in the UK in the year 2000.
#' These data first appeared as the example in
#' Figures 3 and 4 of
#' M.K. Heun, A. Owen, and P.E. Brockway.
#' Figures 3, 7, and 11 of
#' M.K. Heun, A. Owen, and P.E. Brockway. 2018.
#' A physical supply-use table framework for energy analysis on the energy conversion chain.
#' Sustainability Research Institute Paper 111,
#' University of Leeds, School of Earth and Environment,
#' Sustainability Research Institute,
#' Leeds, England,
#' 13 November 2017.
#' Applied Energy,
#' Vol. 226,
#' pp. 1134-1162.
#'
#' @format A data frame with 36 rows and 7 variables:
#' \describe{
Expand All @@ -22,5 +20,5 @@
#' \item{Product}{the energy product involved in this flow}
#' \item{E.ktoe}{magnitude of the energy flow in ktoe}
#' }
#' @source \url{http://www.see.leeds.ac.uk/fileadmin/Documents/research/sri/workingpapers/sri-wp111.pdf}
#' @source \doi{10.1016/j.apenergy.2018.05.109}
"UKEnergy2000"
57 changes: 28 additions & 29 deletions R/expand.R
@@ -1,38 +1,37 @@
#' Expand a "tidy" data frame with matsindf-style matrices to a "tidy" data frame with each matrix entry as an observation
#' Expand a `matsindf` data frame
#'
#' A data frame with \pkg{matsindf}-style matrices contains matrices with names \code{matnames}
#' in the column specified by \code{matvals}).
#' An IO-style matrix has named rows and columns.
#' In addition, \pkg{matsindf}-style matrices have "types" for row and column information, such as "Commodities", "Industries",
#' "Products", or "Machines".
#' Any tidy data frame of matrices (in which each row represents one matrix observation)
#' can also be represented as a tidy data frame
#' with each non-zero matrix entry as an observation on its own row.
#' This function (and `collapse_to_matrices()`) convert between the two representations.
#'
#' Names for output columns are specified in the \code{rownames}, \code{colnames},
#' \code{rowtypes}, and \code{coltypes}, arguments.
#' The entries of the \pkg{matsindf}-style matrices are stored in an output column named \code{values}.
#' Names for output columns are specified in the `rownames`, `colnames`,
#' `rowtypes`, and `coltypes`, arguments.
#' The entries of the \pkg{matsindf}-style matrices are stored in an output column named `values.`
#'
#' @param .DF the data frame containing \pkg{matsindf}-style matrices.
#' (\code{.DF} may also be a named list of matrices, in which case
#' @param .DF The data frame containing \pkg{matsindf}-style matrices.
#' (`.DF` may also be a named list of matrices, in which case
#' names of the matrices are taken from the names of items in the list and
#' list items are expected to be matrices.)
#' @param matnames name of the column in \code{.DF} containing matrix names (a string).
#' Default is "\code{matnames}".
#' @param matvals name of the column in \code{.DF} containing IO-style matrices or constants (a string),
#' @param matnames The name of the column in `.DF` containing matrix names (a string).
#' Default is "matnames".
#' @param matvals The name of the column in `.DF` containing IO-style matrices or constants (a string),
#' This will also be the name of the column containing matrix entries in the output data frame.
#' Default is "\code{matvals}".
#' @param rownames name for the output column of row names (a string).
#' Default is "\code{rownames}".
#' @param colnames name for the output column of column names (a string).
#' Default is "\code{colnames}".
#' @param rowtypes optional name for the output column of row types (a string).
#' Default is "\code{rowtypes}".
#' @param coltypes optional name for the output column of column types (a string)
#' Default is "\code{coltypes}".
#' @param drop if specified, the value to be dropped from output,
#' For example, \code{drop = 0} will cause \code{0} entries in the matrices to be deleted from output.
#' If \code{NA}, no values are dropped from output.
#' Default is \code{NA}.
#' Default is "matvals".
#' @param rownames The name for the output column of row names (a string).
#' Default is "rownames".
#' @param colnames The name for the output column of column names (a string).
#' Default is "colnames".
#' @param rowtypes An optional name for the output column of row types (a string).
#' Default is "rowtypes".
#' @param coltypes The optional name for the output column of column types (a string)
#' Default is "coltypes".
#' @param drop If specified, the value to be dropped from output,
#' For example, `drop = 0` will cause `0` entries in the matrices to be deleted from output.
#' If `NA`, no values are dropped from output.
#' Default is `NA`.
#'
#' @return a tidy data frame containing expanded \pkg{matsindf}-style matrices
#' @return A tidy data frame containing expanded \pkg{matsindf}-style matrices
#'
#' @export
#'
Expand All @@ -55,7 +54,7 @@
#' ptype, ptype, ptype, ptype, NA, NA),
#' coltypes = c(itype, itype, itype, itype, itype, ptype, ptype,
#' itype, itype, itype, itype, NA, NA),
#' vals = c( 11 , 22, 11 , 22 , 23 , 11 , 22 ,
#' vals = c(11 , 22, 11 , 22 , 23 , 11 , 22 ,
#' 11 , 12 , 11 , 22, 0.2, 0.3)) %>%
#' group_by(Country, Year, matrix)
#' mats <- collapse_to_matrices(tidy, matnames = "matrix", rownames = "row", colnames = "col",
Expand Down
16 changes: 11 additions & 5 deletions R/matsindf_apply.R
Expand Up @@ -54,7 +54,7 @@
#' @param FUN the function to be applied to `.dat`.
#' @param ... named arguments to be passed by name to `FUN`.
#'
#' @return a named list or a data frame. (See details.)
#' @return A named list or a data frame. (See details.)
#'
#' @export
#'
Expand Down Expand Up @@ -87,7 +87,7 @@
#' # All arguments are supplied by named arguments in ..., but mix them up.
#' # Note that the named arguments override the items in .dat
#' matsindf_apply(list(a = 1, b = 2, z = 10), FUN = example_fun, a = "z", b = "b")
#' # Warning is issued when an output item has same name as an input item.
#' # A warning is issued when an output item has same name as an input item.
#' matsindf_apply(list(a = 1, b = 2, c = 10), FUN = example_fun, a = "c", b = "b")
matsindf_apply <- function(.dat = NULL, FUN, ...){
if (!is.null(.dat)) {
Expand All @@ -97,7 +97,6 @@ matsindf_apply <- function(.dat = NULL, FUN, ...){
stop(".dat must be a data frame or a list in matsindf_apply, was ", class(.dat))
}
}
# .dat is NULL (the default)
types <- matsindf_apply_types(...)

# Note that is.list(.dat) covers the cases where .dat is either a list or a data frame.
Expand Down Expand Up @@ -129,8 +128,13 @@ matsindf_apply <- function(.dat = NULL, FUN, ...){
out_list <- Map(f = FUN, ...) %>%
unname() %>%
purrr::transpose()
numrows <- length(out_list[[1]])
# Work around a possible error condition here.
numcols <- length(out_list)
if (numcols == 0) {
numrows <- 0
} else {
numrows <- length(out_list[[1]])
}
# Create a data frame filled with NA values.
out_df <- data.frame(matrix(NA, nrow = numrows, ncol = numcols)) %>%
magrittr::set_names(names(out_list))
Expand Down Expand Up @@ -162,7 +166,9 @@ matsindf_apply <- function(.dat = NULL, FUN, ...){
# extract a column from .dat.
# So, eliminate all NULLs from the ... strings.
use_dots_not_null <- use_dots[which(!as.logical(lapply(use_dots, is.null)))]
arg_cols <- lapply(use_dots_not_null, FUN = function(colname){return(.dat[[colname]])})
arg_cols <- lapply(use_dots_not_null, FUN = function(colname){
.dat[[colname]]
})
# If one of the ... strings is not a name of a column in .dat,
# it is, practically speaking, a missing argument, and we should treat it as such.
# If an arg is not present in .dat, it will be NULL in arg_cols.
Expand Down

0 comments on commit bb095f8

Please sign in to comment.