Skip to content

Commit

Permalink
Use .mapply
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Nov 14, 2024
1 parent 2a2db76 commit 683b96e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions R/dist_sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ support.dist_sample <- function(x, ...) {
#' @method Math dist_sample
#' @export
Math.dist_sample <- function(x, ...) {
x <- mapply(.Generic, parameters(x)$x, ..., SIMPLIFY = FALSE)
x <- .mapply(.Generic, list(parameters(x)$x, ...))
names(x) <- "x"
enclass_dist(x, "dist_sample")
}
Expand All @@ -155,7 +155,7 @@ Ops.dist_sample <- function(e1, e2) {
e2 <- parameters(e2)$x
}

x <- mapply(.Generic, e1, e2, SIMPLIFY = FALSE)
x <- .mapply(.Generic, list(e1, e2))
names(x) <- "x"
enclass_dist(x, "dist_sample")
}
4 changes: 2 additions & 2 deletions R/distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ vec_arith.distribution.default <- function(op, x, y, ...){
y <- x[["y"]]
if(is_distribution(y)) y <- vec_data(y)
x <- x[["x"]]
out <- mapply(get(op), x = vec_data(x), y = y, SIMPLIFY = FALSE)
out <- .mapply(get(op), list(x = vec_data(x), y = y))
}
vec_restore(out, x)
}
Expand All @@ -563,7 +563,7 @@ vec_arith.numeric.distribution <- function(op, x, y, ...){
x <- vec_recycle_common(x = x, y = y)
y <- x[["y"]]
x <- x[["x"]]
out <- mapply(get(op), x = x, y = vec_data(y), SIMPLIFY = FALSE)
out <- .mapply(get(op), list(x = x, y = vec_data(y)))
vec_restore(out, y)
}

Expand Down
8 changes: 4 additions & 4 deletions R/hdr.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ new_hdr <- function(lower = list_of(.ptype = double()),


out <- vec_recycle_common(lower = lower, upper = upper)
mapply(
.mapply(
function(l,u) if (any(u<l, na.rm = TRUE)) abort("`upper` can't be lower than `lower`."),
l = out[["lower"]], u = out[["upper"]]
list(l = out[["lower"]], u = out[["upper"]])
)
out[["level"]] <- vctrs::vec_recycle(size, vec_size(out[[1]]))

Expand Down Expand Up @@ -67,14 +67,14 @@ is_hdr <- function(x) {

#' @export
format.hdr <- function(x, justify = "right", ...) {
out <- mapply(function(l,u,s) {
out <- .mapply(function(l,u,s) {
limit <- paste(
format(l, justify = justify, ...),
format(u, justify = justify, ...),
sep = ", "
)
limit <- paste0("[", limit, "]", collapse = "")
paste0(limit, s)
}, l = field(x, "lower"), u = field(x, "upper"), s = field(x, "level"))
}, list(l = field(x, "lower"), u = field(x, "upper"), s = field(x, "level")))
as.vector(out, "character")
}

0 comments on commit 683b96e

Please sign in to comment.