Skip to content

Commit

Permalink
Merge branch 'release-0.3.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHeun committed Jan 25, 2023
2 parents de7baa0 + 6044b6d commit f8bba84
Show file tree
Hide file tree
Showing 47 changed files with 1,755 additions and 1,216 deletions.
78 changes: 20 additions & 58 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- master
- develop
- release-*
branches: [master, develop, release-*]
pull_request:
branches:
- master
- develop
branches: [master, develop]
schedule:
# Build main branch daily at 7 AM UTC, 2 AM EST, 3 AM EDT.
- cron: "0 7 * * *"
Expand All @@ -26,65 +21,32 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Restore R package cache
if: runner.os != 'Windows'
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}
extra-packages: any::rcmdcheck
needs: check

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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,7 +13,7 @@ License: MIT + file LICENSE
Language: en-US
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.0
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Depends: R (>= 2.10)
Imports:
Expand All @@ -27,6 +27,7 @@ Imports:
Suggests:
covr,
ggplot2,
Hmisc,
knitr,
RCLabels,
rmarkdown,
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2022
YEAR: 2023
COPYRIGHT HOLDER: Matthew Kuperus Heun
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit f8bba84

Please sign in to comment.