Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 27, 2024
1 parent 309d929 commit b420e97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ BREAKING CHANGES
* Argument `drop_na` in `data_match()` is deprecated now. Please use `remove_na`
instead.

* The `"diff"` method in `smoothness()` was revised and now has a reversed
interpretation. Documentation was updated accordingly. (#374).

CHANGES

* The `select` argument, which is available in different functions to select
Expand Down
31 changes: 15 additions & 16 deletions R/smoothness.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ smoothness.numeric <- function(x,
}

if (method == "cor") {
smooth <- stats::cor(utils::head(x, length(x) - lag), utils::tail(x, length(x) - lag))
smooth_value <- stats::cor(utils::head(x, length(x) - lag), utils::tail(x, length(x) - lag))
} else {
diff <- standardize(diff(x))

Check warning on line 61 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/smoothness.R,line=61,col=5,[object_overwrite_linter] 'diff' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 61 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/smoothness.R,line=61,col=5,[object_overwrite_linter] 'diff' is an exported object from package 'base'. Avoid re-using such symbols.
smooth <- 1 - mean((diff(diff) ** 2) / 4) # Note the reversal to match the other method
smooth_value <- 1 - mean((diff(diff) ** 2) / 4) # Note the reversal to match the other method
}

if (!is.null(iterations)) {
if (!requireNamespace("boot", quietly = TRUE)) {
insight::format_warning("Package 'boot' needed for bootstrapping SEs.")
} else {
if (requireNamespace("boot", quietly = TRUE)) {
results <- boot::boot(
data = x,
statistic = .boot_smoothness,
Expand All @@ -74,12 +72,14 @@ smoothness.numeric <- function(x,
lag = lag
)
out_se <- stats::sd(results$t, na.rm = TRUE)
smooth <- data.frame(Smoothness = smooth, SE = out_se)
smooth_value <- data.frame(Smoothness = smooth_value, SE = out_se)
} else {
insight::format_warning("Package 'boot' needed for bootstrapping SEs.")
}
}

class(smooth) <- unique(c("parameters_smoothness", class(smooth)))
smooth
class(smooth_value) <- unique(c("parameters_smoothness", class(smooth_value)))
smooth_value
}


Expand All @@ -89,14 +89,13 @@ smoothness.data.frame <- function(x,
lag = 1,
iterations = NULL,
...) {
.smoothness <-
lapply(
x,
smoothness,
method = method,
lag = lag,
iterations = iterations
)
.smoothness <- lapply(
x,
smoothness,
method = method,
lag = lag,
iterations = iterations
)
.smoothness <- cbind(Parameter = names(.smoothness), do.call(rbind, .smoothness))
class(.smoothness) <- unique(c("parameters_smoothness", class(.smoothness)))
.smoothness
Expand Down
2 changes: 1 addition & 1 deletion man/smoothness.Rd

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

0 comments on commit b420e97

Please sign in to comment.