Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 12, 2024
1 parent a8554a9 commit 47c60b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
linters: linters_with_defaults(
absolute_path_linter = NULL,
commented_code_linter = NULL,
cyclocomp_linter = cyclocomp_linter(25),
cyclocomp_linter = cyclocomp_linter(125),
extraction_operator_linter = NULL,
implicit_integer_linter = NULL,
line_length_linter(120),
namespace_linter = NULL,
nonportable_path_linter = NULL,
object_name_linter = NULL,
object_length_linter(50),
library_call_linter = NULL,
object_usage_linter = NULL,
todo_comment_linter = NULL,
undesirable_function_linter(c("mapply" = NA, "sapply" = NA, "setwd" = NA)),
Expand Down
27 changes: 20 additions & 7 deletions R/n_clusters_easystats.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ n_clusters_silhouette <- function(x,
#' }
#' }
#' @export
n_clusters_dbscan <- function(x, standardize = TRUE, include_factors = FALSE, method = c("kNN", "SS"), min_size = 0.1, eps_n = 50, eps_range = c(0.1, 3), ...) {
n_clusters_dbscan <- function(x,
standardize = TRUE,
include_factors = FALSE,
method = c("kNN", "SS"),
min_size = 0.1,
eps_n = 50,
eps_range = c(0.1, 3),
...) {
method <- match.arg(method)
t0 <- Sys.time()
x <- .prepare_data_clustering(x, include_factors = include_factors, standardize = standardize, ...)
Expand Down Expand Up @@ -250,7 +257,13 @@ n_clusters_hclust <- function(x,


#' @keywords internal
.n_clusters_factoextra <- function(x, method = "wss", standardize = TRUE, include_factors = FALSE, clustering_function = stats::kmeans, n_max = 10, ...) {
.n_clusters_factoextra <- function(x,
method = "wss",
standardize = TRUE,
include_factors = FALSE,
clustering_function = stats::kmeans,
n_max = 10,
...) {
x <- .prepare_data_clustering(x, include_factors = include_factors, standardize = standardize, ...)

insight::check_if_installed("factoextra")
Expand All @@ -265,31 +278,31 @@ n_clusters_hclust <- function(x,

#' @export
print.n_clusters_elbow <- function(x, ...) {
insight::print_color(paste0("The Elbow method, that aims at minimizing the total intra-cluster variation (i.e., the total within-cluster sum of square), suggests that the optimal number of clusters is ", attributes(x)$n, "."), "green")
insight::print_color(paste0("The Elbow method, that aims at minimizing the total intra-cluster variation (i.e., the total within-cluster sum of square), suggests that the optimal number of clusters is ", attributes(x)$n, "."), "green") # nolint
invisible(x)
}

#' @export
print.n_clusters_gap <- function(x, ...) {
insight::print_color(paste0("The Gap method, that compares the total intracluster variation of k clusters with their expected values under null reference distribution of the data, suggests that the optimal number of clusters is ", attributes(x)$n, "."), "green")
insight::print_color(paste0("The Gap method, that compares the total intracluster variation of k clusters with their expected values under null reference distribution of the data, suggests that the optimal number of clusters is ", attributes(x)$n, "."), "green") # nolint
invisible(x)
}

#' @export
print.n_clusters_silhouette <- function(x, ...) {
insight::print_color(paste0("The Silhouette method, based on the average quality of clustering, suggests that the optimal number of clusters is ", attributes(x)$n, "."), "green")
insight::print_color(paste0("The Silhouette method, based on the average quality of clustering, suggests that the optimal number of clusters is ", attributes(x)$n, "."), "green") # nolint
invisible(x)
}

#' @export
print.n_clusters_dbscan <- function(x, ...) {
insight::print_color(paste0("The DBSCAN method, based on the total clusters sum of squares, suggests that the optimal eps = ", attributes(x)$eps, " (with min. cluster size set to ", attributes(x)$min_size, "), which corresponds to ", attributes(x)$n, " clusters."), "green")
insight::print_color(paste0("The DBSCAN method, based on the total clusters sum of squares, suggests that the optimal eps = ", attributes(x)$eps, " (with min. cluster size set to ", attributes(x)$min_size, "), which corresponds to ", attributes(x)$n, " clusters."), "green") # nolint
invisible(x)
}

#' @export
print.n_clusters_hclust <- function(x, ...) {
insight::print_color(paste0("The bootstrap analysis of hierachical clustering highlighted ", attributes(x)$n, " significant clusters."), "green")
insight::print_color(paste0("The bootstrap analysis of hierachical clustering highlighted ", attributes(x)$n, " significant clusters."), "green") # nolint
invisible(x)
}

Expand Down
6 changes: 3 additions & 3 deletions R/print_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ print_md.parameters_efa_summary <- function(x, digits = 3, ...) {
table_caption <- "(Explained) Variance of Components"

if ("Parameter" %in% names(x)) {
x$Parameter <- c("Eigenvalues", "Variance Explained", "Variance Explained (Cumulative)", "Variance Explained (Proportion)")
x$Parameter <- c("Eigenvalues", "Variance Explained", "Variance Explained (Cumulative)", "Variance Explained (Proportion)") # nolint
} else if ("Component" %in% names(x)) {
names(x) <- c("Component", "Eigenvalues", "Variance Explained", "Variance Explained (Cumulative)", "Variance Explained (Proportion)")
names(x) <- c("Component", "Eigenvalues", "Variance Explained", "Variance Explained (Cumulative)", "Variance Explained (Proportion)") # nolint
}
insight::export_table(x, digits = digits, format = "markdown", caption = table_caption, align = "firstleft")
}
Expand Down Expand Up @@ -327,7 +327,7 @@ print_md.equivalence_test_lm <- function(x, digits = 2, ci_brackets = c("(", ")"
}

if (!is.null(rope)) {
names(formatted_table)[names(formatted_table) == "% in ROPE"] <- sprintf("%% in ROPE (%.*f, %.*f)", digits, rope[1], digits, rope[2])
names(formatted_table)[names(formatted_table) == "% in ROPE"] <- sprintf("%% in ROPE (%.*f, %.*f)", digits, rope[1], digits, rope[2]) # nolint
}

insight::export_table(formatted_table, format = "markdown", caption = table_caption, align = "firstleft")
Expand Down
9 changes: 7 additions & 2 deletions R/select_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,15 @@ select_parameters.merMod <- function(model,
)


# Using MuMIn's dredge(): works nicely BUT throws unnecessary warnings and requires to set global options for na.action even tho no NaNs.
# Using MuMIn's dredge(): works nicely BUT throws unnecessary warnings and
# requires to set global options for na.action even tho no NaNs.
# The code is here: https://github.com/cran/MuMIn/blob/master/R/dredge.R Maybe it could be reimplemented?
# insight::check_if_installed("MuMIn")
# model <- lmer(Sepal.Width ~ Sepal.Length * Petal.Width * Petal.Length + (1 | Species), data = iris, na.action = na.fail)
# model <- lmer(
# Sepal.Width ~ Sepal.Length * Petal.Width * Petal.Length + (1 | Species),
# data = iris,
# na.action = na.fail
# )
# summary(MuMIn::get.models(MuMIn::dredge(model), 1)[[1]])

best
Expand Down

0 comments on commit 47c60b5

Please sign in to comment.