Skip to content

Commit

Permalink
add 'collate_pkgstats' fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Jul 10, 2024
1 parent a492882 commit 841b63c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: githist
Title: Code analyses traced along the 'git' history of a package
Version: 0.0.1.007
Version: 0.0.1.008
Authors@R:
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
34 changes: 32 additions & 2 deletions R/githist-fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,37 @@ githist <- function (path) {
h <- gert::git_log (repo = path_cp, max = 1e6)

res <- pbapply::pblapply (seq_len (nrow (h)), function (i) {
g <- gert::git_reset_soft (ref = h$commit [i], repo = path_cp)
run_one_pkgstats (path = path_cp)
g <- gert::git_reset_hard (ref = h$commit [i], repo = path_cp)
pkg_date <- h$time [i]
run_one_pkgstats (path = path_cp, pkg_date = pkg_date)
})

collate_pkgstats (res)
}

collate_pkgstats <- function (x) {
nms <- names (x [[1]])
nms2df <- nms [seq_len (which (nms == "loc") - 1L)]
desc_data <- lapply (nms2df, function (i) {
unlist (lapply (x, function (j) j [[i]]))
})
desc_data <- data.frame (do.call (cbind, desc_data))
names (desc_data) <- nms2df
desc_data$date <- lapply (x, function (i) strftime (i$date, "%y-%m-%d %H:%M:%S"))

nms_int <- nms2df [-seq_len (which (nms2df == "date"))]
for (n in nms_int) {
desc_data [[n]] <- as.integer (desc_data [[n]])
}

loc <- do.call (rbind, lapply (x, function (i) i$loc))
stats <- do.call (rbind, lapply (x, function (i) i$stats))
stats$measure <- gsub ("[0-9]+$", "", rownames (stats))
rownames (stats) <- NULL

list (
desc_data = desc_data,
loc = loc,
stats = stats
)
}
13 changes: 11 additions & 2 deletions R/pkgstats-data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
run_one_pkgstats <- function (path) {
run_one_pkgstats <- function (path, pkg_date) {

s <- pkgstats::pkgstats (path)

Expand Down Expand Up @@ -26,18 +26,27 @@ run_one_pkgstats <- function (path) {
n_ext_pkgs <- nrow (ext_calls) - 1L
ext_calls <- mn_med_sum (ext_calls$n [ext_calls$package != "base"])

s$loc <- cbind (
package = s$desc$package,
version = s$desc$version,
date = pkg_date,
s$loc
)

list (
package = s$desc$package,
version = s$desc$version,
date = s$desc$date,
date = pkg_date,
n_aut = s$desc$aut,
n_ctb = s$desc$ctb,
n_fns = n_fns,
n_ext_pkgs = n_ext_pkgs,
base_calls = base_calls,
loc = s$loc,
stats = data.frame (
package = s$desc$package,
version = s$desc$version,
date = pkg_date,
doclines = doclines,
npars = npars,
loc = loc,
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/githist",
"issueTracker": "https://github.com/ropensci-review-tools/githist/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.0.1.007",
"version": "0.0.1.008",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 841b63c

Please sign in to comment.