Skip to content

Commit

Permalink
Merge pull request #22 from rjdemetra/develop
Browse files Browse the repository at this point in the history
v2.1.0 - last improvements
  • Loading branch information
palatej authored Apr 18, 2024
2 parents fbf5055 + a92fcb8 commit 1bf3bcf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
11 changes: 8 additions & 3 deletions R/1_moving_average.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,20 @@ setReplaceMethod("[",
})
#' @rdname filters_operations
#' @export
cbind.moving_average <- function(...){
cbind.moving_average <- function(..., zero_as_na = FALSE){
all_mm <- list(...)
new_lb <- min(sapply(all_mm, lower_bound))
new_ub <- max(sapply(all_mm, upper_bound))
nb_uterms <- max(sapply(all_mm, function(x) lower_bound(x) + length(x)))
if (zero_as_na) {
blank_value <- NA
} else {
blank_value <- 0
}
new_mm <- lapply(all_mm, function(x){
c(rep(0, abs(new_lb - lower_bound(x))),
c(rep(blank_value, abs(new_lb - lower_bound(x))),
coef(x),
rep(0, abs(nb_uterms - (lower_bound(x) + length(x))))
rep(blank_value, abs(nb_uterms - (lower_bound(x) + length(x))))
)
})
new_mm <- do.call(cbind, new_mm)
Expand Down
5 changes: 3 additions & 2 deletions R/2_finite_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ setMethod("/",
})
#' @method as.matrix finite_filters
#' @export
as.matrix.finite_filters <- function(x, sfilter = TRUE, rfilters = TRUE, lfilters = FALSE, ...) {
as.matrix.finite_filters <- function(x, sfilter = TRUE, rfilters = TRUE, lfilters = FALSE, zero_as_na = FALSE, ...) {
sfilter_s <- rfilters_s <- lfilters_s <-
index_s <- index_r <- index_l <- NULL
if (!any(sfilter, rfilters, lfilters))
Expand All @@ -336,7 +336,8 @@ as.matrix.finite_filters <- function(x, sfilter = TRUE, rfilters = TRUE, lfilter
rfilters_s <- x@rfilters
index_r <- seq(length(x@rfilters) - 1, 0)
}
mat <- do.call(cbind, c(lfilters_s, sfilter_s, rfilters_s))
mat <- do.call(cbind, c(lfilters_s, sfilter_s, rfilters_s,
list(zero_as_na = zero_as_na)))
colnames(mat) <- sprintf("q=%i", c(index_l, index_s, index_r))
mat
}
Expand Down
4 changes: 2 additions & 2 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ plot_coef.moving_average <- function(x, nxlab = 7, add = FALSE, ...){
plot_coef.finite_filters <- function(x, nxlab = 7, add = FALSE,
zero_as_na = TRUE, q = 0, legend = length(q) > 1,
legend.pos = "topright", ...){
plot_coef(x = as.matrix(x),
plot_coef(x = as.matrix(x, zero_as_na = zero_as_na),
nxlab = nxlab, add = add,
zero_as_na = zero_as_na, q = q, legend = legend,
zero_as_na = FALSE, q = q, legend = legend,
legend.pos = legend.pos, ...)
}

Expand Down
2 changes: 1 addition & 1 deletion man/filters_operations.Rd

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

0 comments on commit 1bf3bcf

Please sign in to comment.