From b3dbae883ed05d3f8a9aeec01e993abd6892ea78 Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 22 Nov 2022 12:13:47 +0100 Subject: [PATCH] add convert_trawl_cols fn to post-process archive trawl data --- .pre-commit-config.yaml | 1 + DESCRIPTION | 2 +- R/archive-trawl.R | 49 +++++++++++++++++++++++++++++++++++++++++ codemeta.json | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b30a915..fb6229d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,6 +8,7 @@ repos: args: [--style_pkg=spaceout, --style_fun=spaceout_style] additional_dependencies: - ropensci-review-tools/spaceout + - styler #- id: roxygenize #additional_dependencies: #- pkgbuild diff --git a/DESCRIPTION b/DESCRIPTION index 75aa58e..2103a3c 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: pkgstats Title: Metrics of R Packages -Version: 0.1.1.067 +Version: 0.1.1.068 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/archive-trawl.R b/R/archive-trawl.R index 6e50947..2ee9959 100644 --- a/R/archive-trawl.R +++ b/R/archive-trawl.R @@ -460,3 +460,52 @@ get_pkg_version <- function (path) { c (pkg, v) } + +#' Internal function to convert columns in result of archive trawl to expected, +#' generally numeric, types. +#' @noRd +convert_trawl_columns <- function (x) { + + int_cols <- c ( + "^files\\_", + "^loc\\_", + "^blank\\_", + "^comment\\_", + "^indentation$", + "^rel\\_space$", + "^num\\_", + "^desc\\_n\\_", + "^n\\_fns\\_(r|s)", + "^n\\_edges", + "^n\\_clusters" + ) + num_cols <- c ( + "^rel\\_space\\_", + "^nexpr$", + "^rel\\_space\\_", + "^data\\_size\\_", + "^n\\_fns\\_per", + "^npars\\_", + "^doclines\\_per\\_", + "^docchars\\_per\\_", + "^centrality\\_", + "^node\\_degree\\_", + "^cpl\\_instability" + ) + + cols <- names (x) + + int_cols <- lapply (int_cols, function (i) grep (i, cols)) + int_cols <- sort (unlist (int_cols)) + for (i in int_cols) { + storage.mode (x [[i]]) <- "integer" + } + + num_cols <- lapply (num_cols, function (i) grep (i, cols)) + num_cols <- sort (unlist (num_cols)) + for (i in num_cols) { + storage.mode (x [[i]]) <- "numeric" + } + + return (x) +} diff --git a/codemeta.json b/codemeta.json index 6fb0ac1..67e7b76 100644 --- a/codemeta.json +++ b/codemeta.json @@ -11,7 +11,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/pkgstats", "issueTracker": "https://github.com/ropensci-review-tools/pkgstats/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.1.067", + "version": "0.1.1.068", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",