Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
^touchstone$
^codecov\.yml$
^paper$
^\.git-blame-ignore-revs$
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# normed repo to lf
d3462dbbdf1ed84120a39a9f6ac17311fb798423
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto eol=lf
*.rda binary
*.RData binary
*.rds binary
2 changes: 1 addition & 1 deletion .github/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.html
*.html
5 changes: 5 additions & 0 deletions .github/workflows/rcmdcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ jobs:
writeLines(rd_lines, rd_file)
shell: Rscript {0}

- name: Install macOS R system libraries
if: runner.os == 'macOS'
run: |
sudo Rscript -e 'source("https://mac.R-project.org/bin/install.R"); install.libs("gettext")'

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
Expand Down
128 changes: 64 additions & 64 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
# 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:
name: test-coverage.yaml
permissions:
contents: read
id-token: write
jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v6
- 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, any::xml2
needs: coverage
- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
shell: Rscript {0}
- uses: codecov/codecov-action@v7
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
files: ./cobertura.xml
plugins: noop
disable_search: true
use_oidc: true
- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
- name: Upload test results
if: failure()
uses: actions/upload-artifact@v7
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
# 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:

name: test-coverage.yaml

permissions:
contents: read
id-token: write

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

steps:
- uses: actions/checkout@v6

- 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, any::xml2
needs: coverage

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

- uses: codecov/codecov-action@v7
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
files: ./cobertura.xml
plugins: noop
disable_search: true
use_oidc: true

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

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v7
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ LazyData: false
URL: https://mc-stan.org/posterior/, https://discourse.mc-stan.org/
BugReports: https://github.com/stan-dev/posterior/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
VignetteBuilder: knitr
Config/roxygen2/version: 8.0.0
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ S3method(anyDuplicated,rvar)
S3method(anyDuplicated,rvar_factor)
S3method(anyNA,rvar)
S3method(aperm,rvar)
S3method(as.array,rvar)
S3method(as.data.frame,rvar)
S3method(as.list,rvar)
S3method(as.matrix,rvar)
S3method(as.vector,rvar)
S3method(as_draws,default)
S3method(as_draws,draws)
Expand Down
3 changes: 3 additions & 0 deletions R/rvar-.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ new_rvar <- function(x = double(), .nchains = 1L) {
#' @export
draws_of <- function(x, with_chains = FALSE) {
with_chains <- as_one_logical(with_chains)
if (!is_rvar(x) && length(x) && is.list(x) && all(sapply(x, is_rvar))) {
x <- rvar_list_to_rvar(x)
}
draws <- attr(x, "draws")

if (with_chains) {
Expand Down
11 changes: 10 additions & 1 deletion R/rvar-apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
#'
#' @export
rvar_apply <- function(.x, .margin, .f, ...) {
.x_orig <- .x
if (is_rvar(.x)) {
.f_orig <- match.fun(.f)
.x <- as.array(.x)
.f <- function(x, ...) {
.f_orig(rvar_list_to_rvar(x), ...)
}
}

# this should return a list of rvars
rvar_list <- apply(.x, .margin, .f, ...)
if (!is.list(rvar_list) || !all(sapply(rvar_list, is_rvar))) {
Expand Down Expand Up @@ -90,7 +99,7 @@ rvar_apply <- function(.x, .margin, .f, ...) {
}
# restore marginal dimnames
marginal_dim_i <- seq_along(marginal_dim)
out <- copy_dimnames(.x, .margin, out, marginal_dim_i)
out <- copy_dimnames(.x_orig, .margin, out, marginal_dim_i)
}

out
Expand Down
32 changes: 31 additions & 1 deletion R/rvar-cast.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,37 @@ as.list.rvar <- function(x, ...) {
out
}

#' @export
as.array.rvar <- function(x, ...) {
out <- as.list(as.vector(x))
dim(out) <- dim(x)
dimnames(out) <- dimnames(x)
out
}

#' @export
as.matrix.rvar <- function(x, ...) {
if (length(dim(x)) != 2) {
stop("Cannot coerce an rvar with ", length(dim(x)), " dimensions to a matrix.")
}
as.array.rvar(x, ...)
}

#' Collapse a list of rvars from `as.array.rvar()` back into an rvar
#' @noRd
rvar_list_to_rvar <- function(x) {
x_dim <- dim(x)
x_dimnames <- dimnames(x)
x <- do.call(c, unname(as.vector(x)))
if (!is.null(x_dim)) {
dim(x) <- x_dim
if (length(x_dim) > 1) {
dimnames(x) <- x_dimnames
}
}
x
}

#' @importFrom rlang as_label
#' @export
as.data.frame.rvar <- function(x, ..., optional = FALSE) {
Expand All @@ -185,7 +216,6 @@ as_tibble.rvar <- function(x, ...) {
as_tibble(as.data.frame(value, optional = FALSE), ...)
}


# vctrs proxy / restore --------------------------------------------------------

invalidate_rvar_cache = function(x) {
Expand Down
28 changes: 14 additions & 14 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
comment: false
coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
3 changes: 3 additions & 0 deletions man/as_rvar_factor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/draws.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/draws_array.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/draws_df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/draws_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/draws_matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/draws_rvars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading