Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some linting #34

Merged
merged 20 commits into from
Jan 28, 2025
Merged
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
17 changes: 17 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

^.*\.Rproj$
^\.Rproj\.user$

Expand All @@ -6,6 +7,7 @@

^README\.Rmd$
^README-.*\.png$
^README\.html$

^Meta$
^docs$
Expand All @@ -24,4 +26,19 @@ cran-comments.md

^revdep$
^reconf\.sh$

^pom\.xml$

^CITATION\.cff$
^LICENSE.md$

^\.httr-oauth$
^\.zenodo\.json$

^checklist.yml$
^codecov\.yml$
^data-raw$
^dev$

^man-roxygen$
^organisation.yml$
48 changes: 35 additions & 13 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
linters: linters_with_defaults(
linters: lintr::all_linters(
indentation_linter = NULL,
trailing_blank_lines_linter = NULL,
trailing_whitespace_linter = NULL,
assignment_linter = NULL,
whitespace_linter = NULL,
brace_linter = NULL,
# line_length_linter = lintr::line_length_linter(80L),
line_length_linter = lintr::line_length_linter(200L),
infix_spaces_linter = NULL,
paren_body_linter = NULL,
#paren_body_linter = NULL,
indentation_linter = NULL,
function_left_parentheses_linter = NULL,
spaces_left_parentheses_linter = NULL,
#function_left_parentheses_linter = NULL,
commas_linter = NULL,
quotes_linter = NULL,
spaces_inside_linter = NULL,
vector_logic_linter = NULL,
seq_linter = NULL,
#vector_logic_linter = NULL,
#seq_linter = NULL,
object_length_linter = NULL,
semicolon_linter = NULL,
cyclocomp_linter = NULL,
object_usage_linter = NULL,
object_name_linter = NULL,
line_length_linter = NULL,
commented_code_linter = NULL
commented_code_linter = NULL,
extraction_operator_linter = NULL,
undesirable_function_linter = NULL,
nonportable_path_linter = NULL,
implicit_integer_linter = NULL,
numeric_leading_zero_linter = NULL,
fixed_regex_linter = NULL,
unused_import_linter = NULL,
#absolute_path_linter = NULL,
library_call_linter = NULL,
keyword_quote_linter = NULL,
missing_package_linter = NULL,
unnecessary_concatenation_linter = NULL,
strings_as_factors_linter = NULL,
#class_equals_linter = NULL,
namespace_linter = NULL,
inner_combine_linter = NULL,
#paste_linter = NULL,
unnecessary_lambda_linter = NULL,
function_argument_linter = NULL,
if_not_else_linter = NULL,
unnecessary_lambda_linter = NULL,
boolean_arithmetic_linter = NULL,
condition_message_linter = NULL,
undesirable_operator_linter = NULL,
#nested_ifelse_linter = NULL,
unnecessary_nested_if_linter = NULL,
todo_comment_linter = NULL
)
encoding: "UTF-8"
5 changes: 2 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]

### Added
Expand All @@ -16,9 +17,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Changed

* `filter()` correction when the length of the series equals the length of the filter.

* `confint_filter()` uses by default a Student distribution instead of a Normal distribution.


## [2.1.1] - 2024-07-12

### Changed
Expand All @@ -31,9 +32,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* New functions to compute functions to compute diagnostics and goodness of fit of filtered series: cross validation (`cv()`) and cross validate estimate (`cve()`), leave-one-out cross validation estimate (`loocve`), CP statistic (`cp()`) and Rice's T statistics (`rt()`).

* New function `confint_filter()` to compute confidence intervals for filtered series.

* New function `is.finite_filters()`.

* New parameter `zero_as_na` in `cbind.moving_average`, boolean indicating if trealing and leading zeros added to have a matrix form should be replaced by `NA`.


Expand Down
40 changes: 20 additions & 20 deletions R/1_moving_average.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ NULL
#' s <- y * s_mm
#' plot(s)
#' @export
moving_average <- function(x, lags = -length(x), trailing_zero = FALSE, leading_zero = FALSE){
moving_average <- function(x, lags = -length(x), trailing_zero = FALSE, leading_zero = FALSE) {
if (inherits(x, "moving_average"))
return(x)
x <- as.numeric(x)
if (trailing_zero)
x <- rm_trailing_zero_or_na(x)
if (leading_zero){
if (leading_zero) {
new_x <- rm_leading_zero_or_na(x)
lags <- lags - (length(new_x) - length(x))
x <- new_x
Expand All @@ -95,15 +95,15 @@ moving_average <- function(x, lags = -length(x), trailing_zero = FALSE, leading_
upper_bound = upper_bound)
res
}
.jd2ma <- function(jobj, trailing_zero = FALSE){
.jd2ma <- function(jobj, trailing_zero = FALSE) {
x <- .jcall(jobj, "[D", "weightsToArray")
lags <- .jcall(jobj, "I", "getLowerBound")
moving_average(x, lags, trailing_zero = trailing_zero)
}
.ma2jd <- function(x){
.ma2jd <- function(x) {
lags <- lower_bound(x)
coefs <- as.numeric(coef(x))
if (length(x) == 1){
if (length(x) == 1) {
coefs <- .jarray(coefs)
}
.jcall("jdplus/toolkit/base/core/math/linearfilters/FiniteFilter",
Expand All @@ -113,60 +113,60 @@ moving_average <- function(x, lags = -length(x), trailing_zero = FALSE, leading_
}
#' @rdname moving_average
#' @export
is.moving_average <- function(x){
is.moving_average <- function(x) {
is(x, "moving_average")
}
#' @importFrom stats coef coefficients end qnorm qt ts.union
#' @export
coef.moving_average <- function(object, ...){
coef.moving_average <- function(object, ...) {
coefs <- object@coefficients
return(coefs)
}
#' @rdname moving_average
#' @export
is_symmetric <- function(x){
is_symmetric <- function(x) {
# .jcall(.ma2jd(x), "Z", "isSymmetric")
(upper_bound(x) == (-lower_bound(x))) &&
isTRUE(all.equal(coef(x), rev(coef(x)), check.attributes = FALSE))
}
#' @rdname moving_average
#' @export
upper_bound <- function(x){
upper_bound <- function(x) {
x@upper_bound
}
#' @rdname moving_average
#' @export
lower_bound <- function(x){
lower_bound <- function(x) {
x@lower_bound
}
#' @rdname moving_average
#' @export
mirror <- function(x){
mirror <- function(x) {
.jd2ma(.jcall(.ma2jd(x), "Ljdplus/toolkit/base/core/math/linearfilters/FiniteFilter;", "mirror"))
}
#' @method rev moving_average
#' @rdname moving_average
#' @export
rev.moving_average <- function(x){
rev.moving_average <- function(x) {
mirror(x)
}
#' @rdname moving_average
#' @export
length.moving_average <- function(x){
length.moving_average <- function(x) {
length(coef(x))
}
#' @rdname moving_average
#' @export
to_seasonal <- function(x, s){
to_seasonal <- function(x, s) {
UseMethod("to_seasonal", x)
}
#' @export
to_seasonal.default <- function(x, s){
to_seasonal.default <- function(x, s) {
lb <- lower_bound(x)
up <- upper_bound(x)
coefs <- coef(x)
new_coefs <- c(unlist(lapply(coefs[-length(x)],
function(x){
function(x) {
c(x, rep(0, s - 1))
})),
coefs[length(x)])
Expand All @@ -175,7 +175,7 @@ to_seasonal.default <- function(x, s){

#' @rdname filters_operations
#' @export
sum.moving_average <- function(..., na.rm = FALSE){
sum.moving_average <- function(..., na.rm = FALSE) {
sum(
unlist(lapply(list(...),
function(x) sum(coef(x),na.rm = na.rm)
Expand Down Expand Up @@ -223,7 +223,7 @@ setReplaceMethod("[",
})
#' @rdname filters_operations
#' @export
cbind.moving_average <- function(..., zero_as_na = FALSE){
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))
Expand All @@ -233,7 +233,7 @@ cbind.moving_average <- function(..., zero_as_na = FALSE){
} else {
blank_value <- 0
}
new_mm <- lapply(all_mm, function(x){
new_mm <- lapply(all_mm, function(x) {
c(rep(blank_value, abs(new_lb - lower_bound(x))),
coef(x),
rep(blank_value, abs(nb_uterms - (lower_bound(x) + length(x))))
Expand All @@ -245,7 +245,7 @@ cbind.moving_average <- function(..., zero_as_na = FALSE){
}
#' @rdname filters_operations
#' @export
rbind.moving_average <- function(...){
rbind.moving_average <- function(...) {
t(cbind(...))
}
#' @rdname filters_operations
Expand Down
Loading
Loading