Skip to content

Commit 66c8086

Browse files
committed
address smnnlt follow-up: streamline test suite and drop purrr
- rewrote test suite from ~600 to 373 focused assertions (0 fail / 0 warn / 0 skip on local devtools::test()) - replaced expect_true(is.data.frame()) with expect_s3_class(), expect_equal(length()) with expect_length() - removed redundant gg-class checks now covered by vdiffr snapshots - deleted test-smoke-and-errors.R, test-uncovered-branches.R and other fragmented test files - replaced mock helpers with inst/extdata/ example data where possible - removed purrr from dependencies entirely - removed CITATION.cff (flagged by R CMD check) - cleaned up NAMESPACE, DESCRIPTION, and .Rbuildignore - R CMD check: 0 errors, 0 warnings
1 parent 6920ffc commit 66c8086

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1822
-4488
lines changed

.Rbuildignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
^package\.json$
9898
^package-lock\.json$
9999
^strava_api.*\.md$
100-
^提交指南.*\.md$
100+
^submission_guide.*\.md$
101101
^export_data$
102102
^athlytics_downloads_raw_data\.csv$
103103
^Athlytics_.*\.tar\.gz$
@@ -108,7 +108,7 @@
108108
^analysis_output$
109109
^Athlytics$
110110
^\.lang$
111-
^.*调试.*$
111+
^.*debug.*$
112112
^create_multi_athlete_sample_data\.R$
113113
^regenerate_figures\.R$
114114
^.*coverage.*\.R$
@@ -154,3 +154,8 @@
154154
^\.pytest_cache$
155155
^review.*\.md$
156156
^document_output\.log$
157+
^PACKAGES$
158+
^PACKAGES\.gz$
159+
^PACKAGES\.rds$
160+
^coverage_output\.txt$
161+
^test-ef-adv\.Rout$

CITATION.cff

Lines changed: 0 additions & 21 deletions
This file was deleted.

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Suggests:
3434
R.utils,
3535
readr,
3636
rmarkdown,
37-
testthat (>= 3.0.0),
37+
testthat (>= 3.1.5),
3838
vdiffr,
3939
xml2
4040
Remotes:
@@ -43,4 +43,5 @@ Additional_repositories: https://grimbough.r-universe.dev
4343
VignetteBuilder: knitr
4444
RoxygenNote: 7.3.3
4545
Roxygen: list(markdown = TRUE)
46+
Config/testthat/edition: 3
4647
NeedsCompilation: no

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export(plot_with_reference)
2626
export(quality_summary)
2727
export(summarize_quality)
2828
export(theme_athlytics)
29-
import(ggplot2)
3029
importFrom(dplyr,"%>%")
3130
importFrom(dplyr,first)
3231
importFrom(rlang,"%||%")

R/calculate_ef.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,26 @@ calculate_ef <- function(activities_data,
433433
#' @return Data frame with EF calculation results
434434
#'
435435
#' @examples
436-
#' \dontrun{
437-
#' # Parse activity file and calculate EF from streams
438-
#' streams <- parse_activity_file("activity_12345.fit")
439-
#' ef_result <- calculate_ef_from_stream(
440-
#' stream_data = streams,
436+
#' # Example with synthetic stream data
437+
#' set.seed(42)
438+
#' n <- 3600
439+
#' stream <- data.frame(
440+
#' time = 0:(n - 1),
441+
#' heartrate = round(150 + rnorm(n, 0, 2)),
442+
#' velocity_smooth = 3.0 + rnorm(n, 0, 0.05),
443+
#' distance = cumsum(rep(3.0, n))
444+
#' )
445+
#' result <- calculate_ef_from_stream(
446+
#' stream_data = stream,
441447
#' activity_date = as.Date("2025-01-15"),
442448
#' act_type = "Run",
443449
#' ef_metric = "speed_hr",
444-
#' min_steady_minutes = 20,
445-
#' steady_cv_threshold = 0.08,
446-
#' min_hr_coverage = 0.9,
447-
#' quality_control = "filter"
450+
#' min_steady_minutes = 10,
451+
#' steady_cv_threshold = 0.1,
452+
#' min_hr_coverage = 0.8,
453+
#' quality_control = "off"
448454
#' )
449-
#' }
455+
#' print(result)
450456
#'
451457
#' @export
452458
calculate_ef_from_stream <- function(stream_data, activity_date, act_type, ef_metric,

R/cohort_reference.R

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,28 @@ cohort_reference <- function(data,
218218
#' "p25_p75" (inner quartiles), "p05_p95" (outer 5-95 range), "p50" (median).
219219
#' Default c("p25_p75", "p05_p95", "p50").
220220
#' @param alpha Transparency for reference bands (0-1). Default 0.15.
221-
#' @param colors Named list of colors for bands. Default uses viridis colors.
221+
#' @param colors Named list of colors for bands. Default uses Nature-inspired palette colors.
222222
#'
223223
#' @return A ggplot object with added reference bands.
224224
#'
225225
#' @export
226226
#'
227227
#' @examples
228-
#' \dontrun{
229-
#' # Create base plot
230-
#' p <- plot_acwr(acwr_df = individual_acwr)
228+
#' # Example: add reference bands to an ACWR plot
229+
#' data("sample_acwr", package = "Athlytics")
230+
#' set.seed(42)
231+
#' cohort <- dplyr::bind_rows(
232+
#' dplyr::mutate(sample_acwr, athlete_id = "A1"),
233+
#' dplyr::mutate(sample_acwr, athlete_id = "A2",
234+
#' acwr_smooth = acwr_smooth * runif(nrow(sample_acwr), 0.9, 1.1))
235+
#' )
236+
#' ref <- suppressWarnings(
237+
#' calculate_cohort_reference(cohort, metric = "acwr_smooth", min_athletes = 2)
238+
#' )
239+
#' p <- suppressMessages(plot_acwr(sample_acwr, highlight_zones = FALSE))
240+
#' p_ref <- add_reference_bands(p, reference_data = ref)
241+
#' print(p_ref)
231242
#'
232-
#' # Add reference bands
233-
#' p_with_ref <- add_reference_bands(p, reference_data = cohort_ref)
234-
#' print(p_with_ref)
235-
#' }
236243
add_reference_bands <- function(p,
237244
reference_data,
238245
bands = c("p25_p75", "p05_p95", "p50"),
@@ -261,7 +268,8 @@ add_reference_bands <- function(p,
261268
data = ref_wide,
262269
ggplot2::aes(x = .data$date, ymin = .data$p05, ymax = .data$p95),
263270
fill = colors$p05_p95,
264-
alpha = alpha
271+
alpha = alpha,
272+
inherit.aes = FALSE
265273
)
266274
}
267275

@@ -270,7 +278,8 @@ add_reference_bands <- function(p,
270278
data = ref_wide,
271279
ggplot2::aes(x = .data$date, ymin = .data$p25, ymax = .data$p75),
272280
fill = colors$p25_p75,
273-
alpha = alpha * 1.5
281+
alpha = alpha * 1.5,
282+
inherit.aes = FALSE
274283
)
275284
}
276285

@@ -280,7 +289,8 @@ add_reference_bands <- function(p,
280289
ggplot2::aes(x = .data$date, y = .data$p50),
281290
color = colors$p50,
282291
linetype = "dashed",
283-
linewidth = 0.8
292+
linewidth = 0.8,
293+
inherit.aes = FALSE
284294
)
285295
}
286296

R/color_palettes.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ athlytics_palette_vibrant <- function() {
7373
#' theme_athlytics()
7474
#'
7575
#' @export
76-
#' @import ggplot2
7776
theme_athlytics <- function(base_size = 13, base_family = "") {
7877
ggplot2::theme_minimal(base_size = base_size, base_family = base_family) +
7978
ggplot2::theme(

R/flag_quality.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,17 @@ flag_quality <- function(streams,
239239
#' @export
240240
#'
241241
#' @examples
242-
#' \dontrun{
243-
#' flagged_data <- flag_quality(stream_data)
242+
#' # Create sample stream and summarize quality
243+
#' set.seed(42)
244+
#' stream_data <- data.frame(
245+
#' time = seq(0, 3600, by = 1),
246+
#' heartrate = pmax(60, pmin(200, rnorm(3601, mean = 150, sd = 10))),
247+
#' watts = pmax(0, rnorm(3601, mean = 200, sd = 20)),
248+
#' velocity_smooth = pmax(0, rnorm(3601, mean = 3.5, sd = 0.3))
249+
#' )
250+
#' flagged_data <- flag_quality(stream_data, sport = "Run")
244251
#' summarize_quality(flagged_data)
245-
#' }
252+
#'
246253
summarize_quality <- function(flagged_streams) {
247254
if (!is.data.frame(flagged_streams)) {
248255
stop("`flagged_streams` must be a data frame from flag_quality().")

R/load_local_activities.R

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,24 @@
5252
#' follow applicable privacy regulations when using this data for research purposes.
5353
#'
5454
#' @examples
55-
#' \dontrun{
56-
#' # Load all activities from local CSV
57-
#' activities <- load_local_activities("strava_export_data/activities.csv")
55+
#' # Example using built-in sample CSV
56+
#' csv_path <- system.file("extdata", "activities.csv", package = "Athlytics")
57+
#' if (nzchar(csv_path)) {
58+
#' activities <- load_local_activities(csv_path)
59+
#' head(activities)
60+
#' }
5861
#'
59-
#' # Load directly from ZIP archive (no need to extract manually!)
62+
#' \dontrun{
63+
#' # Load from a local Strava export ZIP archive
6064
#' activities <- load_local_activities("export_12345678.zip")
6165
#'
62-
#' # Load only running activities from 2023
66+
#' # Filter by date and activity type
6367
#' activities <- load_local_activities(
6468
#' path = "export_12345678.zip",
6569
#' start_date = "2023-01-01",
6670
#' end_date = "2023-12-31",
6771
#' activity_types = "Run"
6872
#' )
69-
#'
70-
#' # Use with Athlytics functions
71-
#' acwr_data <- calculate_acwr(activities, load_metric = "distance_km")
72-
#' plot_acwr(acwr_data, highlight_zones = TRUE)
73-
#'
74-
#' # Multi-metric analysis
75-
#' ef_data <- calculate_ef(activities, ef_metric = "speed_hr")
76-
#' plot_ef(ef_data, add_trend_line = TRUE)
7773
#' }
7874
#'
7975
#' @export

R/parse_activity_file.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
#' Returns NULL if file cannot be parsed or does not exist.
1414
#'
1515
#' @examples
16+
#' # Parse a built-in example TCX file
17+
#' tcx_path <- system.file("extdata", "activities", "example.tcx", package = "Athlytics")
18+
#' if (nzchar(tcx_path)) {
19+
#' streams <- parse_activity_file(tcx_path)
20+
#' if (!is.null(streams)) head(streams)
21+
#' }
22+
#'
1623
#' \dontrun{
17-
#' # Parse a FIT file
24+
#' # Parse a FIT file from a Strava export
1825
#' streams <- parse_activity_file("activity_12345.fit", export_dir = "strava_export/")
19-
#'
20-
#' # Parse a compressed GPX file
21-
#' streams <- parse_activity_file("activity_12345.gpx.gz")
2226
#' }
2327
#'
2428
#' @export

0 commit comments

Comments
 (0)