Skip to content

Commit

Permalink
next try to fix issue #834
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Jan 19, 2020
1 parent cc23b2a commit 0bd1111
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/extract_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,13 @@ extract_draws_gp <- function(bterms, samples, sdata, data,
# @param old_ranef same as 'ranef' but based on the original formula
# @return a named list with one element per group containing posterior draws
# of levels used in the data as well as additional meta-data
extract_draws_ranef <- function(ranef, samples, sdata, resp, old_ranef,
extract_draws_ranef <- function(ranef, samples, sdata, old_ranef, resp = NULL,
sample_new_levels = "uncertainty", ...) {
if (!nrow(ranef)) {
return(NULL)
}
# ensures subsetting 'ranef' by 'resp' works correctly
resp <- resp %||% ""
groups <- unique(ranef$group)
out <- named_list(groups, list())
for (g in groups) {
Expand All @@ -561,7 +563,8 @@ extract_draws_ranef <- function(ranef, samples, sdata, resp, old_ranef,
)
}
# only extract draws of effects specified in the new formula
used_rpars <- match(ranef_g$cn, old_ranef_g$cn)
cols_match <- c("coef", "resp", "dpar", "nlpar")
used_rpars <- which(find_rows(old_ranef_g, ls = ranef_g[cols_match]))
used_rpars <- outer(seq_len(nlevels), (used_rpars - 1) * nlevels, "+")
used_rpars <- as.vector(used_rpars)
rsamples <- rsamples[, used_rpars, drop = FALSE]
Expand Down
5 changes: 5 additions & 0 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ subset_keep_attr <- function(x, y) {
x
}

'%||%' <- function(x, y) {
if (is.null(x)) x <- y
x
}

# check if 'x' is a whole number (integer)
is_wholenumber <- function(x, tol = .Machine$double.eps) {
if (is.numeric(x)) {
Expand Down

0 comments on commit 0bd1111

Please sign in to comment.