From 47c60b5e2c153a86e8f5b865e91cf59c6c7864e5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Jun 2024 08:51:37 +0200 Subject: [PATCH] lintr --- .lintr | 3 ++- R/n_clusters_easystats.R | 27 ++++++++++++++++++++------- R/print_md.R | 6 +++--- R/select_parameters.R | 9 +++++++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.lintr b/.lintr index b0e8abefe..c575e7c95 100644 --- a/.lintr +++ b/.lintr @@ -1,7 +1,7 @@ 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), @@ -9,6 +9,7 @@ linters: linters_with_defaults( 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)), diff --git a/R/n_clusters_easystats.R b/R/n_clusters_easystats.R index 62cdc5a39..6a9205a82 100644 --- a/R/n_clusters_easystats.R +++ b/R/n_clusters_easystats.R @@ -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, ...) @@ -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") @@ -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) } diff --git a/R/print_md.R b/R/print_md.R index cc997fe3a..f7bc40e64 100644 --- a/R/print_md.R +++ b/R/print_md.R @@ -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") } @@ -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") diff --git a/R/select_parameters.R b/R/select_parameters.R index 6ce6760fe..0061fe552 100644 --- a/R/select_parameters.R +++ b/R/select_parameters.R @@ -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