Skip to content

Commit

Permalink
Merge pull request #45 from poissonconsulting/upkeep
Browse files Browse the repository at this point in the history
  • Loading branch information
joethorley authored Sep 23, 2024
2 parents 33d0fbe + be327ac commit 7a61f2e
Show file tree
Hide file tree
Showing 45 changed files with 430 additions and 388 deletions.
36 changes: 9 additions & 27 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# 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: [main, master]
pull_request:
branches: [main, master]
schedule:
- cron: '0 8 * * 0'

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
Expand All @@ -25,24 +22,19 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}
# use 4.0 or 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: 'oldrel-4'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

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

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

Expand All @@ -60,14 +52,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true

- name: action-slack
if: failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
uses: 8398a7/[email protected]
with:
status: ${{ job.status }}
author_name: "github action: ${{github.workflow}}"
fields: repo, ref, commit, author, message

build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
6 changes: 4 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:

name: pkgdown

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
Expand All @@ -22,7 +24,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand All @@ -41,7 +43,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,54 @@ on:

name: test-coverage

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

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

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
covr::codecov(
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ License: MIT + file LICENSE
URL: https://github.com/poissonconsulting/nlist
BugReports: https://github.com/poissonconsulting/nlist/issues
Depends:
R (>= 3.5)
R (>= 4.0)
Imports:
abind,
chk,
Expand All @@ -60,5 +60,5 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
VignetteBuilder: knitr
22 changes: 22 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ S3method(nterms,mcmc)
S3method(nterms,mcmc.list)
S3method(nterms,nlist)
S3method(nterms,nlists)
S3method(numericise,list)
S3method(pars,mcmc)
S3method(pars,mcmc.list)
S3method(pars,nlist)
Expand Down Expand Up @@ -152,9 +153,30 @@ importFrom(abind,abind)
importFrom(coda,as.mcmc)
importFrom(coda,as.mcmc.list)
importFrom(coda,thin)
importFrom(extras,fill_all)
importFrom(extras,fill_na)
importFrom(extras,lower)
importFrom(extras,pvalue)
importFrom(extras,svalue)
importFrom(extras,upper)
importFrom(extras,zscore)
importFrom(generics,tidy)
importFrom(purrr,transpose)
importFrom(stats,aggregate)
importFrom(stats,median)
importFrom(term,as.term)
importFrom(term,as_term)
importFrom(term,complete_terms)
importFrom(universals,"pars<-")
importFrom(universals,bind_iterations)
importFrom(universals,collapse_chains)
importFrom(universals,estimates)
importFrom(universals,nchains)
importFrom(universals,niters)
importFrom(universals,npdims)
importFrom(universals,nsims)
importFrom(universals,nterms)
importFrom(universals,pars)
importFrom(universals,pdims)
importFrom(universals,set_pars)
importFrom(universals,split_chains)
9 changes: 4 additions & 5 deletions R/as-nlist.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ as_nlist <- function(x, ...) {
#' @export
as.nlist <- function(x, ...) {
deprecate_warn("0.1.1",
what = "nlist::as.nlist()",
with = "nlist::as_nlist()"
what = "nlist::as.nlist()",
with = "nlist::as_nlist()"
)
UseMethod("as_nlist")
}
Expand All @@ -31,7 +31,7 @@ as_nlist.numeric <- function(x, ...) {
chk_not_any_na(names(x))
chk_unique(names(x))
chk_unused(...)

if (!length(x)) {
return(nlist())
}
Expand Down Expand Up @@ -70,7 +70,7 @@ as_nlist.data.frame <- function(x, ...) as_nlist(as.list(x))
#' @export
as_nlist.mcmc <- function(x, ...) {
chk_unused(...)
if(!identical(nrow(x), 1L)) abort_chk("`x` must have one iteration.")
if (!identical(nrow(x), 1L)) abort_chk("`x` must have one iteration.")

x <- complete_terms(x)

Expand All @@ -89,4 +89,3 @@ as_nlist.mcmc.list <- function(x, ...) {

#' @export
as_nlist.nlist <- function(x, ...) x

3 changes: 2 additions & 1 deletion R/as-nlists.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ as_nlists.mcmc.list <- function(x, ...) {
nchains <- nchains(x)
x <- as_mcmc(x)
x <- as_nlists(x)
if(nchains != 1L)
if (nchains != 1L) {
attr(x, "nchains") <- nchains
}
x
}

Expand Down
6 changes: 3 additions & 3 deletions R/as-term-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ as_term_frame <- function(x, ...) {

#' Coerce nlist Object to Data Frame
#'
#' Coerces an nlist object to a data.frame with an term column
#' Coerces an nlist object to a data.frame with an term column
#' and a value column.
#'
#' @export
Expand Down Expand Up @@ -62,7 +62,7 @@ as_term_frame_nlist_impl <- function(x, sample = NULL) {

#' Coerce nlists Object to Data Frame
#'
#' Coerces an nlists object to a data.frame with a term, sample
#' Coerces an nlists object to a data.frame with a term, sample
#' and value column.
#'
#' @export
Expand All @@ -85,7 +85,7 @@ as_term_frame.nlists <- function(x, ...) {
)))
}
x <- mapply(as_term_frame_nlist_impl, x,
sample = 1:length(x),
sample = seq_along(x),
SIMPLIFY = FALSE
)
do.call("rbind", x)
Expand Down
24 changes: 12 additions & 12 deletions R/bind-iterations.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ universals::bind_iterations
#' bind_iterations(as_mcmc(nlist(x = 1)), as_mcmc(nlist(x = 3)))
bind_iterations.mcmc <- function(x, x2, ...) {
chk_s3_class(x2, "mcmc")

x <- sort(x)
x2 <- sort(x2)

if (!identical(pars(x), pars(x2))) {
abort_chk("`x` and `x2` must have the same parameters")
}

if (!identical(pdims(x), pdims(x2))) {
abort_chk("`x` and `x2` must have the same parameter dimensions")
}

if (!identical(nchains(x), nchains(x2))) {
abort_chk("`x` and `x2` must have the same number of chains")
}

x <- abind(x, x2, along = 1)
as.mcmc(x)
}
Expand All @@ -32,27 +32,27 @@ bind_iterations.mcmc <- function(x, x2, ...) {
#' @examples
#' bind_iterations(as_mcmc_list(nlist(x = 1)), as_mcmc_list(nlist(x = 3)))
bind_iterations.mcmc.list <- function(x, x2, ...) {
if(!(vld_s3_class(x2, "mcmc.list") || vld_s3_class(x2, "mcmc"))) {
if (!(vld_s3_class(x2, "mcmc.list") || vld_s3_class(x2, "mcmc"))) {
if (!vld_all_identical(lapply(x, lapply, dims))) {
abort_chk("`x2` must inherit from S3 class 'mcmc.list' or 'mcmc'.")
}
}
}

x <- sort(x)
x2 <- sort(x2)

if (!identical(pars(x), pars(x2))) {
abort_chk("`x` and `x2` must have the same parameters")
}

if (!identical(pdims(x), pdims(x2))) {
abort_chk("`x` and `x2` must have the same parameter dimensions")
}

if (!identical(nchains(x), nchains(x2))) {
abort_chk("`x` and `x2` must have the same number of chains")
}

x <- mapply(x, x2, FUN = bind_iterations, SIMPLIFY = FALSE)
set_class(x, "mcmc.list")
}
4 changes: 2 additions & 2 deletions R/chk.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ chk_nlist <- function(x, x_name = NULL) {
chk_named(x, x_name = x_name)
x_name_names <- backtick_chk(p0("names(", unbacktick_chk(x_name), ")"))
chk_pars(names(x), x_name = x_name_names)
chk_not_any_na(names(x), x_name = x_name_names)
chk_unique(names(x), x_name = x_name_names)
chk_not_any_na(names(x), x_name = x_name_names)
chk_unique(names(x), x_name = x_name_names)
chk_all(x, chk_numeric, x_name = x_name)
}

Expand Down
8 changes: 4 additions & 4 deletions R/complete-terms.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @importFrom term complete_terms
#' @export
#' @export
term::complete_terms

#' Complete Terms
Expand All @@ -21,13 +21,13 @@ term::complete_terms
complete_terms.mcmc <- function(x, silent = FALSE, ...) {
chk_flag(silent)
chk_unused(...)

if (!silent && anyNA(colnames(x))) {
wrn("terms with missing values have been dropped")
}

x <- as.matrix(x)
x <- x[,!is.na(colnames(x)), drop = FALSE]
x <- x[, !is.na(colnames(x)), drop = FALSE]
colnames(x) <- as.character(as_term(colnames(x), repair = TRUE))
if (!silent && anyNA(colnames(x))) wrn("invalid terms have been dropped")
x <- x[, !is.na(colnames(x)), drop = FALSE]
Expand All @@ -39,7 +39,7 @@ complete_terms.mcmc <- function(x, silent = FALSE, ...) {
wrn("inconsistent terms have been dropped")
}
x <- x[, consistent, drop = FALSE]

if (!ncol(x)) {
return(coda::as.mcmc(x))
}
Expand Down
3 changes: 2 additions & 1 deletion R/extras.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ as_list_unnamed_default <- function(x, ...) {
x <- as.list(x)
names <- names(x)
attributes(x) <- NULL
if(!is.null(names))
if (!is.null(names)) {
names(x) <- names
}
x
}
Loading

0 comments on commit 7a61f2e

Please sign in to comment.