From 0fb6415b7365750b1fa55b222697ae071ec78717 Mon Sep 17 00:00:00 2001 From: Julian Karch Date: Thu, 30 May 2024 23:19:00 +0200 Subject: [PATCH] small stylistic improvements --- R/calc_APA_factor.R | 2 +- R/checkHTMLdir.R | 6 +++--- R/checkPDFdir.R | 2 +- R/checkdir.R | 8 ++++---- R/decision_error_test.R | 4 ++-- R/error_test.R | 2 +- R/plot.statcheck.R | 2 +- R/process_stats.R | 2 +- R/statcheck.R | 15 ++++++--------- 9 files changed, 20 insertions(+), 23 deletions(-) diff --git a/R/calc_APA_factor.R b/R/calc_APA_factor.R index 625cbed..56a70af 100644 --- a/R/calc_APA_factor.R +++ b/R/calc_APA_factor.R @@ -21,7 +21,7 @@ calc_APA_factor <- function(pRes, Res){ APAfactor <- round(as.numeric(apply(Res, 1, function(x) - APA[which(names(APA) == x["Source"])])), 2) + APA[names(APA) == x["Source"]])), 2) return(APAfactor) diff --git a/R/checkHTMLdir.R b/R/checkHTMLdir.R index 7018cf6..f25a5fe 100644 --- a/R/checkHTMLdir.R +++ b/R/checkHTMLdir.R @@ -9,11 +9,11 @@ checkHTMLdir <- function(dir, dir <- tcltk::tk_choose.dir() } - if (extension == TRUE) { + if (extension) { pat = ".html|.htm" } - if (extension == FALSE) { + if (!extension) { pat = "" } @@ -31,7 +31,7 @@ checkHTMLdir <- function(dir, message("Importing HTML files...") pb <- utils::txtProgressBar(max = length(files), style = 3) - for (i in 1:length(files)) { + for (i in seq_along(files)) { txts[i] <- getHTML(files[i]) utils::setTxtProgressBar(pb, i) } diff --git a/R/checkPDFdir.R b/R/checkPDFdir.R index bc73888..b828464 100644 --- a/R/checkPDFdir.R +++ b/R/checkPDFdir.R @@ -22,7 +22,7 @@ checkPDFdir <- message("Importing PDF files...") pb <- utils::txtProgressBar(max = length(files), style = 3) - for (i in 1:length(files)){ + for (i in seq_along(files)){ txts[i] <- getPDF(files[i]) utils::setTxtProgressBar(pb, i) } diff --git a/R/checkdir.R b/R/checkdir.R index e39078f..c735a82 100644 --- a/R/checkdir.R +++ b/R/checkdir.R @@ -21,14 +21,14 @@ checkdir <- if (htmls) htmlres <- checkHTMLdir(dir, subdir, ...) - if (pdfs & htmls) { + if (pdfs && htmls) { if (!is.null(pdfres) & !is.null(htmlres)) Res <- rbind(pdfres, htmlres) else stop("statcheck did not find any results") } else - if (pdfs & !htmls) { + if (pdfs && !htmls) { if (!is.null(pdfres)) Res <- pdfres else @@ -36,7 +36,7 @@ checkdir <- } else - if (!pdfs & htmls) { + if (!pdfs && htmls) { if (!is.null(htmlres)) Res <- htmlres else @@ -44,7 +44,7 @@ checkdir <- } else - if (!pdfs & !htmls) + if (!pdfs && !htmls) stop("No PDF or HTML found") diff --git a/R/decision_error_test.R b/R/decision_error_test.R index 02e839d..2c6fc77 100644 --- a/R/decision_error_test.R +++ b/R/decision_error_test.R @@ -9,7 +9,7 @@ decision_error_test <- function(reported_p, computed_p, # check errors for different combinations of <>= ------------------------- # treat p = alpha as significant - if(pEqualAlphaSig == TRUE){ + if(pEqualAlphaSig){ if(test_comparison == "="){ if(p_comparison == "="){ @@ -73,7 +73,7 @@ decision_error_test <- function(reported_p, computed_p, return(NA) # treat p = alpha as significant - } else if (pEqualAlphaSig == FALSE){ + } else if (!pEqualAlphaSig){ if(test_comparison == "="){ diff --git a/R/error_test.R b/R/error_test.R index 4322299..34c98e8 100644 --- a/R/error_test.R +++ b/R/error_test.R @@ -44,7 +44,7 @@ error_test <- function(reported_p, test_type, test_stat, # p values smaller or equal to zero are errors --------------------------- - if(pZeroError == TRUE & reported_p <= 0){ + if(pZeroError && reported_p <= 0){ error <- TRUE return(error) } diff --git a/R/plot.statcheck.R b/R/plot.statcheck.R index acc149b..74098a7 100644 --- a/R/plot.statcheck.R +++ b/R/plot.statcheck.R @@ -57,7 +57,7 @@ plot.statcheck <- function( x[[VAR_P_COMPARISON]][ns] <- ">" x[[VAR_REPORTED_P]][ns] <- alpha - if (APAstyle == TRUE) { + if (APAstyle) { # Add vector "Type" to statcheck object, specifying whether observations are # correctly reported, reporting inconsistencies, or decision errors. diff --git a/R/process_stats.R b/R/process_stats.R index 774431a..7d9a8d2 100644 --- a/R/process_stats.R +++ b/R/process_stats.R @@ -51,7 +51,7 @@ process_stats <- function(test_type, test_stat, df1, df2, reported_p, # tailed test, classify the result as consistent # don't apply this correction if OneTailedTests == FALSE, because this already # forces statcheck to treat all results as one-tailed tests - if(OneTailedTxt == TRUE & OneTailedTests == FALSE){ + if(OneTailedTxt && !OneTailedTests){ # select only results where the phrase "one-tailed", "one-sided" or # "directional" was mentioned in text, and that were an error when diff --git a/R/statcheck.R b/R/statcheck.R index 96fe060..c5d3671 100644 --- a/R/statcheck.R +++ b/R/statcheck.R @@ -142,7 +142,7 @@ statcheck <- function(texts, # progress bar. This is mainly useful for the unit tests; otherwise hundreds # of progress bars would be printed during testing and that makes the test # results hard to read - if(messages == TRUE){ + if(messages){ message("Extracting statistics...") pb <- utils::txtProgressBar(max = length(text), style = 3) } @@ -195,14 +195,14 @@ statcheck <- function(texts, rm(nhst) # update the progress bar - if(messages == TRUE){ + if(messages){ utils::setTxtProgressBar(pb, i) } } # close progress bar - if(messages == TRUE){ + if(messages){ close(pb) } @@ -215,11 +215,8 @@ statcheck <- function(texts, # same as the automated 1-tailed test detection (switched on with the # argument: OneTailedTxt). The latter works more subtly (see comments in # process_stats()). - if (OneTailedTests == TRUE) { - two_tailed <- FALSE - } else { - two_tailed <- TRUE - } + two_tailed <- !OneTailedTests + # create empty variables to fill out during the loop Res$Computed <- rep(NA, nrow(Res)) @@ -279,7 +276,7 @@ statcheck <- function(texts, # Return ------------------------------------------------------------------ - if (AllPValues == FALSE) { + if (!AllPValues) { # Return message when there are no results if (nrow(Res) > 0) {