diff --git a/DESCRIPTION b/DESCRIPTION index dfaa7c4..0398366 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: PaRe Type: Package Title: A Way to Perform Code Review or QA on Other Packages -Version: 0.1.15 +Version: 0.1.16 Language: en-US Authors@R: person("Maarten", "van Kessel", email = "m.l.vankessel@erasmusmc.nl", diff --git a/NEWS.md b/NEWS.md index e343d7d..9f02ffb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +PaRe 0.1.16 +========== +1. Use `dplyr::reframe()` instead of `dplyr::summarise()` for dplyr >= 1.2.0 compatability + +PaRe 0.1.15 +========== +1. Updated internal test setup + PaRe 0.1.14 ========== 1. Changed tests so R-CMD-Check passes on depends-only environment diff --git a/R/getDefaultPermittedPackages.R b/R/getDefaultPermittedPackages.R index 3355f07..0db08e9 100644 --- a/R/getDefaultPermittedPackages.R +++ b/R/getDefaultPermittedPackages.R @@ -18,28 +18,38 @@ getParDeps <- function(pkgs, nThreads) { deps <- if (nThreads > 1) { cl <- parallel::makeCluster(nThreads) on.exit(parallel::stopCluster(cl = cl)) - parallel::clusterEvalQ(cl = cl, expr = {library("pak", character.only = TRUE)}) + parallel::clusterEvalQ(cl = cl, expr = { + library("pak", character.only = TRUE) + }) parallel::parLapply(cl = cl, X = pkgs, fun = function(pkg) { - tryCatch({ - res <- pak::pkg_deps(pkg = pkg) - return(res) - }, error = function(e) { - return(NULL) - }, warning = function(w) { - return(res) - }) + tryCatch( + { + res <- pak::pkg_deps(pkg = pkg) + return(res) + }, + error = function(e) { + return(NULL) + }, + warning = function(w) { + return(res) + } + ) }) } else { lapply(X = pkgs, function(pkg) { - tryCatch({ - res <- pak::pkg_deps(pkg = pkg) - return(res) - }, error = function(e) { - return(NULL) - }, warning = function(w) { - return(res) - }) + tryCatch( + { + res <- pak::pkg_deps(pkg = pkg) + return(res) + }, + error = function(e) { + return(NULL) + }, + warning = function(w) { + return(res) + } + ) }) } diff --git a/R/lint.R b/R/lint.R index 5a693f7..425ef18 100644 --- a/R/lint.R +++ b/R/lint.R @@ -151,7 +151,7 @@ lintScore <- function(repo, messages) { pct <- messages %>% dplyr::group_by(.data$type) %>% dplyr::tally() %>% - dplyr::summarise(.data$type, pct = round(.data$n / nLines * 100, 2)) + dplyr::reframe(.data$type, pct = round(.data$n / nLines * 100, 2)) if (nrow(pct) == 0) { message(glue::glue("{nrow(pct)} Lintr messages found")) diff --git a/inst/rmd/report.Rmd b/inst/rmd/report.Rmd index d1a68ea..b812e43 100644 --- a/inst/rmd/report.Rmd +++ b/inst/rmd/report.Rmd @@ -180,11 +180,8 @@ DT::datatable(data.frame( meanDegree = round(mean(igraph::degree(graphData)), 2), meanDistance = round(mean(igraph::distances(graphData)), 2) ), - rownames= FALSE) -}, error = function(e) { - message("Could not get graph data with error:") - message(sprintf("\t%s", e)) -}) + rownames = FALSE +) ``` ### Function use per dependency diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 484effe..1df6163 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -6,20 +6,25 @@ path <- file.path(tempdir(), "glue") repoCloned <- NULL if (!is.null(curl::nslookup("captive.apple.com", error = FALSE))) { - tryCatch({ - clone( - url = "https://github.com/tidyverse/glue", - local_path = path - ) - repoCloned <- TRUE - }, error = function(e) { - repoCloned <- FALSE - }) + tryCatch( + { + clone( + url = "https://github.com/tidyverse/glue", + local_path = path + ) + repoCloned <- TRUE + }, + error = function(e) { + repoCloned <- FALSE + } + ) } else { repoCloned <- FALSE } -withr::defer({ - unlink(path, recursive = TRUE, force = TRUE)}, +withr::defer( + { + unlink(path, recursive = TRUE, force = TRUE) + }, teardown_env() ) diff --git a/vignettes/Documentation.Rmd b/vignettes/Documentation.Rmd index b036c16..50c5fdd 100644 --- a/vignettes/Documentation.Rmd +++ b/vignettes/Documentation.Rmd @@ -234,10 +234,11 @@ PaRe::pkgDiagram(repo = repo) %>% if (fetchedRepo) { if (all(c( require("DiagrammeRsvg", character.only = TRUE), - require("magick", character.only = TRUE)))) { - PaRe::pkgDiagram(repo = repo) %>% - DiagrammeRsvg::export_svg() %>% - magick::image_read_svg() + require("magick", character.only = TRUE) + ))) { + PaRe::pkgDiagram(repo = repo) %>% + DiagrammeRsvg::export_svg() %>% + magick::image_read_svg() } } ``` diff --git a/vignettes/articles/PareReport.Rmd b/vignettes/articles/PareReport.Rmd index 8a486c8..1fbd03d 100644 --- a/vignettes/articles/PareReport.Rmd +++ b/vignettes/articles/PareReport.Rmd @@ -43,66 +43,91 @@ defFuns <- defFuns %>% ``` ```{r summaryDefFunStats, echo=FALSE} -DT::datatable(data.frame( - min = c(min(defFuns$nArgs, na.rm = TRUE), - min(defFuns$size, na.rm = TRUE), - min(defFuns$cycloComp, na.rm = TRUE)), - median = c(median(defFuns$nArgs, na.rm = TRUE), - median(defFuns$size, na.rm = TRUE), - median(defFuns$cycloComp, na.rm = TRUE)), - max = c(max(defFuns$nArgs, na.rm = TRUE), - max(defFuns$size, na.rm = TRUE), - max(defFuns$cycloComp, na.rm = TRUE)), - row.names = c("Number of arguments", - "Lines of code", - "Cyclomatic complexity")), - options = list(dom = 't')) +DT::datatable( + data.frame( + min = c( + min(defFuns$nArgs, na.rm = TRUE), + min(defFuns$size, na.rm = TRUE), + min(defFuns$cycloComp, na.rm = TRUE) + ), + median = c( + median(defFuns$nArgs, na.rm = TRUE), + median(defFuns$size, na.rm = TRUE), + median(defFuns$cycloComp, na.rm = TRUE) + ), + max = c( + max(defFuns$nArgs, na.rm = TRUE), + max(defFuns$size, na.rm = TRUE), + max(defFuns$cycloComp, na.rm = TRUE) + ), + row.names = c( + "Number of arguments", + "Lines of code", + "Cyclomatic complexity" + ) + ), + options = list(dom = "t") +) ``` ```{r echo=FALSE} -gg_nArgs <- defFuns %>% - ggplot2::ggplot()+ - ggplot2::geom_histogram(ggplot2::aes(nArgs), binwidth = 1, - colour = "black", - fill = "grey")+ - ggplot2::theme_minimal()+ +gg_nArgs <- defFuns %>% + ggplot2::ggplot() + + ggplot2::geom_histogram(ggplot2::aes(nArgs), + binwidth = 1, + colour = "black", + fill = "grey" + ) + + ggplot2::theme_minimal() + ggplot2::xlab("Number of arguments") -gg_size <- defFuns %>% - ggplot2::ggplot()+ - ggplot2::geom_histogram(ggplot2::aes(size), binwidth = 1, - colour = "black", - fill = "grey")+ - ggplot2::theme_minimal()+ +gg_size <- defFuns %>% + ggplot2::ggplot() + + ggplot2::geom_histogram(ggplot2::aes(size), + binwidth = 1, + colour = "black", + fill = "grey" + ) + + ggplot2::theme_minimal() + ggplot2::xlab("Lines of code") -gg_cycloComp <- defFuns %>% - ggplot2::ggplot()+ - ggplot2::geom_histogram(ggplot2::aes(cycloComp), binwidth = 1, - colour = "black", - fill = "grey")+ - ggplot2::theme_minimal()+ +gg_cycloComp <- defFuns %>% + ggplot2::ggplot() + + ggplot2::geom_histogram(ggplot2::aes(cycloComp), + binwidth = 1, + colour = "black", + fill = "grey" + ) + + ggplot2::theme_minimal() + ggplot2::xlab("Cyclomatic complexity") cowplot::plot_grid(gg_nArgs, gg_size, gg_cycloComp, nrow = 3) ``` ```{r, warning=FALSE, message=FALSE, echo=FALSE} -p <- defFuns %>% - ggplot2::ggplot(ggplot2::aes(group = name))+ - ggplot2::geom_point(ggplot2::aes(size, cycloComp, - colour = nArgs), - size = 3)+ - ggplot2::scale_colour_gradient(name = "Number of\nargruments", - low = "blue", high = "red") + +p <- defFuns %>% + ggplot2::ggplot(ggplot2::aes(group = name)) + + ggplot2::geom_point( + ggplot2::aes(size, cycloComp, + colour = nArgs + ), + size = 3 + ) + + ggplot2::scale_colour_gradient( + name = "Number of\nargruments", + low = "blue", high = "red" + ) + ggplot2::theme_minimal() + ggplot2::xlab("Lines of code") + ggplot2::ylab("Cyclomatic complexity") + ggplot2::theme(legend.position = "top") - plotly::ggplotly(p, - tooltip = c("group", "colour", - "x", "y")) +plotly::ggplotly(p, + tooltip = c( + "group", "colour", + "x", "y" + ) +) ``` ## Function details @@ -114,15 +139,17 @@ lineBreaks <- c(100, 200) DT::datatable( defFuns %>% - dplyr::mutate(file_start = paste0(.data$fileName, " (from line: ", lineStart, ")")) %>% - dplyr::select("name", "nArgs", "size","cycloComp", "file_start") %>% + dplyr::mutate(file_start = paste0(.data$fileName, " (from line: ", lineStart, ")")) %>% + dplyr::select("name", "nArgs", "size", "cycloComp", "file_start") %>% dplyr::rename( "Function" = "name", "Number of arguments" = "nArgs", "Lines of code" = "size", "Cyclomatic complexity" = "cycloComp", - "Location" = "file_start"), - rownames = FALSE) %>% + "Location" = "file_start" + ), + rownames = FALSE +) %>% DT::formatStyle("Number of arguments", backgroundColor = DT::styleInterval(argBreaks, colours)) %>% DT::formatStyle("Cyclomatic complexity", backgroundColor = DT::styleInterval(complexBreaks, colours)) %>% DT::formatStyle("Lines of code", backgroundColor = DT::styleInterval(lineBreaks, colours)) @@ -132,7 +159,8 @@ DT::datatable( ```{r countLines, echo=FALSE} DT::datatable( PaRe::countPackageLines(repo), - rownames = "# lines of code") + rownames = "# lines of code" +) ``` ## Style adherence, syntax errors and possible semantic issues @@ -140,19 +168,21 @@ DT::datatable( ```{r lintScores, message=FALSE, warning=FALSE, echo=FALSE} lintMsgs <- PaRe::lintRepo(repo) -DT::datatable(PaRe::lintScore(repo, lintMsgs) %>% - dplyr::rename("Percentage of lines assessed" = "pct"), - rownames = FALSE) +DT::datatable( + PaRe::lintScore(repo, lintMsgs) %>% + dplyr::rename("Percentage of lines assessed" = "pct"), + rownames = FALSE +) ``` ### Warnings ```{r lintMessages warnings, message=FALSE, warning=FALSE, echo=FALSE} DT::datatable( lintMsgs %>% - dplyr::filter(type == "warning") %>% - dplyr::group_by(message) %>% - dplyr::tally(sort = TRUE), - rownames= FALSE + dplyr::filter(type == "warning") %>% + dplyr::group_by(message) %>% + dplyr::tally(sort = TRUE), + rownames = FALSE ) ``` @@ -160,10 +190,10 @@ DT::datatable( ```{r lintMessages style, message=FALSE, warning=FALSE, echo=FALSE} DT::datatable( lintMsgs %>% - dplyr::filter(type == "style") %>% - dplyr::group_by(message) %>% - dplyr::tally(sort = TRUE), - rownames= FALSE + dplyr::filter(type == "style") %>% + dplyr::group_by(message) %>% + dplyr::tally(sort = TRUE), + rownames = FALSE ) ``` @@ -181,13 +211,15 @@ DT::datatable(PaRe::checkDependencies(repo = repo, nThreads = 10)) ```{r dependencyGraphStats, message=FALSE, warning=FALSE, echo=FALSE} graphData <- PaRe::getGraphData(repo = repo, nThreads = 10) -DT::datatable(data.frame( - countVertices = length(igraph::V(graphData)), - countEdges = length(igraph::E(graphData)), - meanDegree = round(mean(igraph::degree(graphData)), 2), - meanDistance = round(mean(igraph::distances(graphData)), 2) +DT::datatable( + data.frame( + countVertices = length(igraph::V(graphData)), + countEdges = length(igraph::E(graphData)), + meanDegree = round(mean(igraph::degree(graphData)), 2), + meanDistance = round(mean(igraph::distances(graphData)), 2) ), - rownames= FALSE) + rownames = FALSE +) ``` ### Function use per dependency @@ -196,11 +228,12 @@ funsUsed <- PaRe::getFunctionUse(repo = repo) DT::datatable( funsUsed, - rownames = FALSE) + rownames = FALSE +) ``` ```{r plotFunctionUse, dpi=100, fig.height=25, out.width="100%", message=FALSE, warning=FALSE, echo=FALSE} -function_sub <- funsUsed %>% +function_sub <- funsUsed %>% dplyr::filter(!pkg %in% c("base")) fun_counts <- function_sub %>% @@ -212,16 +245,19 @@ nonPkgFuns <- fun_counts[!fun_counts$fun %in% defFuns$fun, ] ggplot2::ggplot( data = nonPkgFuns, - mapping = ggplot2::aes(x = .data$fun, y = .data$n, fill = .data$pkg)) + + mapping = ggplot2::aes(x = .data$fun, y = .data$n, fill = .data$pkg) +) + ggplot2::geom_col() + ggplot2::facet_wrap( dplyr::vars(.data$pkg), scales = "free_x", - ncol = 2) + + ncol = 2 + ) + ggplot2::theme_bw() + ggplot2::theme( legend.position = "none", - axis.text.x = (ggplot2::element_text(angle = 45, hjust = 1, vjust = 1))) + axis.text.x = (ggplot2::element_text(angle = 45, hjust = 1, vjust = 1)) + ) ``` ## Further reading