Skip to content

Commit 20b9e22

Browse files
authored
Merge pull request #120 from ropensci-review-tools/single-data
Reduce dashboard input to single parameter for #114
2 parents c0d8d3e + cefc97d commit 20b9e22

11 files changed

+101
-68
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: repometrics
22
Title: Metrics for Your Code Repository
3-
Version: 0.1.6.075
3+
Version: 0.1.6.079
44
Authors@R:
55
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265"))

R/data-repo.R

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@
2222
#' @param nyears Parameter <= 1 determining fraction of a year over which data
2323
#' up until `end_date` are collected.
2424
#'
25-
#' @return data
25+
#' @return A list of three forms of data:
26+
#' \enumerate{
27+
#' \item "pkgstats" containing statistics on the historical development of
28+
#' package code, derived from the \pkg{pkgstats} package;
29+
#' \item "rm" containing data from GitHub on the repository, including data on
30+
#' contributors, issues, pull requests, and people watching and starring the
31+
#' repository.
32+
#' \item "contributors" as a named list of data on every individual contributor
33+
#' to the repository, whether by code contributions or GitHub issues or
34+
#' discussions.
35+
#' }
36+
#'
37+
#' @family data
2638
#' @export
2739
repometrics_data <- function (path, step_days = 1L, num_cores = -1L,
2840
ended_at = Sys.time (), nyears = 1) {

R/quarto-dashboard.R

+28-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#' Start quarto dashboard with results of main \link{repometrics_data_repo}
22
#' function.
33
#'
4-
#' @param data_repo Data on repository as returned from
5-
#' \link{repometrics_data_repo} function applied to one package.
6-
#' @param data_users Data on repository developers ("users" in GitHub terms), as
7-
#' returned from \link{repometrics_data_user} function applied to one package.
4+
#' @param data Data on repository and all contributors as returned from
5+
#' \link{repometrics_data} function applied to one package.
86
#' @param action One of "preview", to start and open a live preview of the
97
#' dashboard website, or "render" to render a static version without previewing
108
#' or opening.
@@ -23,25 +21,39 @@
2321
#'
2422
#' @family dashboard
2523
#' @export
26-
repometrics_dashboard <- function (data_repo, data_users, action = "preview",
24+
repometrics_dashboard <- function (data, action = "preview",
2725
ctb_threshold = NULL, max_ctbs = NULL) {
2826

2927
if (!is.null (ctb_threshold)) {
30-
checkmate::assert_numeric (ctb_threshold, len = 1L, lower = 0, upper = 1)
28+
checkmate::assert_numeric (
29+
ctb_threshold,
30+
len = 1L,
31+
lower = 0,
32+
upper = 1
33+
)
3134
if (!is.null (max_ctbs)) {
32-
cli::cli_abort ("Only one of 'ctb_threshold' or 'max_ctbs' may be specified.")
35+
cli::cli_abort (
36+
"Only one of 'ctb_threshold' or 'max_ctbs' may be specified."
37+
)
3338
}
3439
}
3540
if (!is.null (max_ctbs)) {
36-
checkmate::assert_integerish (max_ctbs, len = 1L, lower = 1, upper = length (data_users))
41+
checkmate::assert_integerish (
42+
max_ctbs,
43+
len = 1L,
44+
lower = 1,
45+
upper = length (data$contributors)
46+
)
3747
}
3848

49+
data_ctbs <- data$contributors
50+
data$contributors <- NULL
3951
if (!is.null (ctb_threshold) || !is.null (max_ctbs)) {
40-
data_users <- reduce_data_users (data_users, ctb_threshold, max_ctbs)
52+
data_ctbs <- reduce_data_users (data_ctbs, ctb_threshold, max_ctbs)
4153
}
4254

43-
check_dashboard_arg (data_repo)
44-
data_repo$pkgstats <- timestamps_to_dates (data_repo$pkgstats)
55+
check_dashboard_arg (data)
56+
data$pkgstats <- timestamps_to_dates (data$pkgstats)
4557

4658
requireNamespace ("brio")
4759
requireNamespace ("jsonlite")
@@ -54,16 +66,16 @@ repometrics_dashboard <- function (data_repo, data_users, action = "preview",
5466
path_src <- system.file ("extdata", "quarto", package = "repometrics")
5567
path_dest <- fs::path (fs::path_temp (), "quarto")
5668
dir <- fs::dir_copy (path_src, path_dest, overwrite = TRUE)
57-
saveRDS (data_repo, fs::path (dir, "results-repo.Rds"))
58-
saveRDS (data_users, fs::path (dir, "results-users.Rds"))
69+
saveRDS (data, fs::path (dir, "results-repo.Rds"))
70+
saveRDS (data_ctbs, fs::path (dir, "results-users.Rds"))
5971

60-
dat_user_network <- get_user_network (data_repo, data_users)
72+
dat_user_network <- get_user_network (data, data_ctbs)
6173
jsonlite::write_json (
6274
dat_user_network,
6375
fs::path (dir, "results-user-network.json")
6476
)
6577

66-
pkg_name <- data_repo$pkgstats$desc_data$package [1]
78+
pkg_name <- data$pkgstats$desc_data$package [1]
6779
quarto_insert_pkg_name (dir, pkg_name)
6880

6981
withr::with_dir (dir, {
@@ -248,7 +260,7 @@ timestamps_to_dates <- function (data) {
248260
dplyr::ungroup ()
249261
}
250262

251-
return (dplyr::arrange (i, by = dplyr::desc (date)))
263+
dplyr::arrange (i, by = dplyr::desc (date))
252264
})
253265
}
254266

README.md

+10-17
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,22 @@ pak::pkg_install ("ropensci-review-tools/repometrics")
3636

3737
### Use
3838

39-
The dashboard requires two sources of data, beginning with core data of a focal
40-
repository. Code for that repository must exist in a local directory
41-
corresponding to the single input parameter, `path`:
39+
The `repometrics` package has one main function for collating all data for a
40+
repository:
41+
[`repometrics_data()`](https://docs.ropensci.org/repometrics/reference/repometrics_data.html).
42+
This function has one main parameter, specifying the `path` to a local
43+
directory containing an R package.
4244

4345
``` r
44-
data_repo <- repometrics_data_repo (path)
46+
data <- repometrics_data (path)
4547
```
4648

47-
The second data source is then information on all people who have contributed
48-
to the repository, both by direct code commits and via GitHub. The following
49-
lines extract information on each of those contributors:
49+
A `repometrics` dashboard for the repository can then be launched by passing
50+
those `data` to [the `repometrics_dashboard()`
51+
function](https://docs.ropensci.org/repometrics/reference/repometrics_dashboard.html):
5052

5153
``` r
52-
ctbs <- data_repo$rm$contribs_from_gh_api$login
53-
data_ctbs <- lapply (ctbs, repometrics_data_user)
54-
names (data_ctbs) <- ctbs
55-
```
56-
57-
A `repometrics` dashboard for the repository can then be launched with the
58-
following line:
59-
60-
``` r
61-
repometrics_dashboard (data_repo, data_ctbs)
54+
repometrics_dashboard (data)
6255
```
6356

6457
The dashboard will automatically open in your default browser.

codemeta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"codeRepository": "https://github.com/ropensci-review-tools/repometrics",
99
"issueTracker": "https://github.com/ropensci-review-tools/repometrics/issues",
1010
"license": "https://spdx.org/licenses/GPL-3.0",
11-
"version": "0.1.6.075",
11+
"version": "0.1.6.079",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",

man/repo_pkgstats_history.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/repometrics_dashboard.Rd

+4-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/repometrics_data.Rd

+18-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/repometrics_data_repo.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/repometrics_data_user.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-dashboard.R

+23-23
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,67 @@ pkg <- system.file ("extdata", "testpkg.zip", package = "repometrics")
1111
flist <- unzip (pkg, exdir = fs::path_temp ())
1212
path <- fs::path_dir (flist [1])
1313
pkgstats <- repo_pkgstats_history (path, num_cores = 1L)
14-
data0 <- list (pkgstats = pkgstats, rm = rm_data)
1514

1615
num_users <- 4L
17-
data_users <- lapply (seq_len (num_users), function (i) mock_user_rel_data ())
18-
names (data_users) <- letters [seq_len (length (data_users))]
16+
data_ctbs <- lapply (seq_len (num_users), function (i) mock_user_rel_data ())
17+
names (data_ctbs) <- letters [seq_len (length (data_ctbs))]
18+
19+
data0 <- list (pkgstats = pkgstats, rm = rm_data, contributors = data_ctbs)
1920

2021
# --------- pre-process end --------
2122

2223
test_that ("dashboard input errors", {
2324

2425
data <- data0
2526
expect_error (
26-
repometrics_dashboard (data, data_users, action = "noarg"),
27+
repometrics_dashboard (data, action = "noarg"),
2728
"\\'arg\\' should be one of"
2829
)
2930
names (data) [1] <- "changed"
3031
expect_error (
31-
repometrics_dashboard (data, data_users, action = "render"),
32+
repometrics_dashboard (data, action = "render"),
3233
"Assertion on \\'names\\(data\\)\\' failed\\: Names must be "
3334
)
3435

3536
data$pkgstats$stats <- data$pkgstats$stats [, -1]
3637
expect_error (
37-
repometrics_dashboard (data, data_users, action = "render"),
38+
repometrics_dashboard (data, action = "render"),
3839
"Assertion on \\'names\\(data\\)\\' failed\\: Names must be "
3940
)
4041

4142
data <- data0
4243
data$pkgstats$stats <-
4344
data$pkgstats$stats [-seq_len (nrow (data$pkgstats$stats)), ]
4445
expect_error (
45-
repometrics_dashboard (data, data_users, action = "render"),
46+
repometrics_dashboard (data, action = "render"),
4647
"\\'data\\' contains empty tables."
4748
)
4849

4950
expect_error (
50-
repometrics_dashboard (data, data_users, ctb_threshold = "a"),
51+
repometrics_dashboard (data, ctb_threshold = "a"),
5152
paste0 (
5253
"Assertion on \\'ctb\\_threshold\\' failed\\: ",
5354
"Must be of type \\'numeric\\'"
5455
)
5556
)
5657
expect_error (
57-
repometrics_dashboard (data, data_users, ctb_threshold = 2),
58+
repometrics_dashboard (data, ctb_threshold = 2),
5859
"Assertion on \\'ctb\\_threshold\\' failed\\: Element 1 is not <= 1"
5960
)
6061
expect_error (
61-
repometrics_dashboard (data, data_users, max_ctbs = "a"),
62+
repometrics_dashboard (data, max_ctbs = "a"),
6263
paste0 (
6364
"Assertion on \\'max\\_ctbs\\' failed\\: ",
6465
"Must be of type \\'integerish\\'"
6566
)
6667
)
6768
expect_error (
68-
repometrics_dashboard (data, data_users, max_ctbs = 0),
69+
repometrics_dashboard (data, max_ctbs = 0),
6970
"Assertion on \\'max\\_ctbs\\' failed\\: Element 1 is not >= 1"
7071
)
7172
expect_error (
7273
repometrics_dashboard (
7374
data,
74-
data_users,
7575
ctb_threshold = 0.5,
7676
max_ctbs = 2
7777
),
@@ -81,14 +81,14 @@ test_that ("dashboard input errors", {
8181

8282
test_that ("dashboard build", {
8383

84-
data_repo <- data0
85-
repometrics_dashboard (data_repo, data_users, action = "render")
84+
data <- data0
85+
repometrics_dashboard (data, action = "render")
8686

8787
# Expect quarto docs to have been modified with package name:
8888
path_tmp <- fs::path (fs::path_temp (), "quarto")
8989
expect_true (fs::dir_exists (path_tmp))
9090

91-
pkg_name <- data_repo$pkgstats$desc_data$package [1]
91+
pkg_name <- data$pkgstats$desc_data$package [1]
9292
f_index <- fs::path (path_tmp, "index.qmd")
9393
index_qmd <- brio::read_lines (f_index)
9494
i <- grep ("^title\\:", index_qmd)
@@ -120,11 +120,10 @@ test_that ("dashboard build", {
120120

121121
test_that ("dashboard with user reduction", {
122122

123-
data_repo <- data0
123+
data <- data0
124124
max_ctbs <- 2L
125125
repometrics_dashboard (
126-
data_repo,
127-
data_users,
126+
data,
128127
max_ctbs = max_ctbs,
129128
action = "render"
130129
)
@@ -148,12 +147,13 @@ test_that ("dashboard with user reduction", {
148147

149148
test_that ("reduce_data_users", {
150149

151-
data_users_red <- reduce_data_users (data_users, max_ctb = 2L)
152-
expect_length (data_users, num_users)
153-
expect_length (data_users_red, 2L)
150+
max_ctbs <- 2L
151+
data_ctbs_red <- reduce_data_users (data_ctbs, max_ctbs = max_ctbs)
152+
expect_length (data_ctbs, num_users)
153+
expect_length (data_ctbs_red, max_ctbs)
154154

155-
data_users_red <- reduce_data_users (data_users, ctb_threshold = 0.5)
156-
expect_true (length (data_users_red) < length (data_users))
155+
data_ctbs_red <- reduce_data_users (data_ctbs, ctb_threshold = 0.5)
156+
expect_true (length (data_ctbs_red) < length (data_ctbs))
157157
})
158158

159159
if (fs::dir_exists (path)) {

0 commit comments

Comments
 (0)