Skip to content

Commit 88033fe

Browse files
authored
Merge pull request #49 from pydemull/dev
Dev
2 parents c57598d + 375306d commit 88033fe

15 files changed

+98
-97
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ $run_dev.*
3232
^Meta$
3333
_\.new\.png$
3434
^temp$
35+
^\.github$

.github/workflows/R-CMD-check.yaml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
@@ -19,16 +19,15 @@ jobs:
1919
matrix:
2020
config:
2121
- {os: windows-latest, r: 'release'}
22-
- {os: ubuntu-latest, r: 'release'}
23-
- {os: windows-latest, r: 'devel'}
24-
- {os: ubuntu-latest, r: 'devel'}
22+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
23+
- {os: ubuntu-latest, r: 'oldrel-1'}
2524

2625
env:
2726
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2827
R_KEEP_PKG_SOURCE: yes
2928

3029
steps:
31-
- uses: actions/checkout@v3
30+
- uses: actions/checkout@v4
3231

3332
- uses: r-lib/actions/setup-pandoc@v2
3433

@@ -37,26 +36,13 @@ jobs:
3736
r-version: ${{ matrix.config.r }}
3837
http-user-agent: ${{ matrix.config.http-user-agent }}
3938
use-public-rspm: true
40-
41-
- name: Install sessioninfo
42-
run: |
43-
install.packages("sessioninfo")
44-
shell: Rscript {0}
4539

4640
- uses: r-lib/actions/setup-r-dependencies@v2
4741
with:
4842
extra-packages: any::rcmdcheck
49-
50-
- uses: r-lib/actions/check-r-package@v2
51-
52-
- name: Show testthat output
53-
if: always()
54-
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
55-
shell: bash
43+
needs: check
5644

57-
- name: Upload check results
58-
if: failure()
59-
uses: actions/upload-artifact@main
45+
- uses: r-lib/actions/check-r-package@v2
6046
with:
61-
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
62-
path: check
47+
upload-snapshots: true
48+
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

.github/workflows/test-coverage.yaml

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,50 @@
1-
# Workflow derived from https://github.com/rstudio/shinytest2/tree/main/actions/test-app/example-test-app-description.yaml
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
55
branches: [main, master]
66
pull_request:
77
branches: [main, master]
88

9-
name: Test app w/ {renv}
9+
name: test-coverage
1010

1111
jobs:
12-
test-app:
13-
runs-on: ${{ matrix.config.os }}
14-
15-
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
16-
17-
strategy:
18-
fail-fast: false
19-
matrix:
20-
config:
21-
- {os: ubuntu-latest, r: release}
22-
12+
test-coverage:
13+
runs-on: windows-latest
2314
env:
2415
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
25-
R_KEEP_PKG_SOURCE: yes
2616

2717
steps:
28-
- uses: actions/checkout@v3
29-
30-
- uses: r-lib/actions/setup-pandoc@v2
18+
- uses: actions/checkout@v4
3119

3220
- uses: r-lib/actions/setup-r@v2
3321
with:
34-
r-version: ${{ matrix.config.r }}
3522
use-public-rspm: true
3623

37-
- uses: r-lib/actions/setup-renv@v2
38-
39-
- uses: rstudio/shinytest2/actions/test-app@actions/v1
24+
- uses: r-lib/actions/setup-r-dependencies@v2
4025
with:
41-
app-dir: "."
42-
26+
extra-packages: any::covr
27+
needs: coverage
28+
4329
- name: Test coverage
44-
run: covr::codecov(quiet = FALSE, clean = FALSE)
30+
run: |
31+
covr::codecov(
32+
quiet = FALSE,
33+
clean = FALSE,
34+
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
35+
)
4536
shell: Rscript {0}
46-
37+
38+
- name: Show testthat output
39+
if: always()
40+
run: |
41+
## --------------------------------------------------------------------
42+
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
43+
shell: bash
44+
45+
- name: Upload test results
46+
if: failure()
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: coverage-test-failures
50+
path: ${{ runner.temp }}/package

R/compute_accumulation_metrics.R

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,16 @@ compute_accumulation_metrics <- function(
9898
zoom_to = "23:59:59"
9999
){
100100

101-
# Filtering data based on selected dates and time periods, and adding a
102-
# column containing "SED", NON-SED", or "Nonwear" labels
101+
# Getting selected dates
103102
if (is.null(dates)) {
104103
selected_dates <- attributes(as.factor(data$date))$levels
105104
} else {
106105
selected_dates <- attributes(as.factor(dates))$levels
107106
}
108107

109-
# Fix bug: Convert Nas to "Nonwear"
110-
data[[col_cat_int]] <- dplyr::if_else(is.na(data[[col_cat_int]]), "Nonwear", data[[col_cat_int]])
111-
112-
data <-
108+
# Filtering data based on selected dates and time periods, and adding a
109+
# column 'new_intensity_category' containing "SED", PA, or "Nonwear" values
110+
data <-
113111
data %>%
114112
dplyr::filter(
115113
date %in% as.Date(selected_dates) &
@@ -127,28 +125,28 @@ if (is.null(dates)) {
127125
"SED",
128126
dplyr::if_else(
129127
.data[[col_cat_int]] == "Nonwear",
130-
"Nonwear",
131-
dplyr::if_else(is.na(.data[[col_cat_int]]), "Nonwear", "Nonwear")
128+
"Nonwear", NA
132129
)
133130
)
134131
)
135132
)
136133

137-
# Updating bouts IDs
134+
# Setting IDs for the new PA/SED/Nonwear bouts
138135
data$new_intensity_category <- as.factor(data$new_intensity_category)
139136
data$new_intensity_category_num <- as.numeric(as.character(forcats::fct_recode(data$new_intensity_category , "0" = "Nonwear", "1" = "SED", "2" = "PA")))
140137
data$new_bout <- cumsum(c(1, as.numeric(diff(data$new_intensity_category_num))!= 0))
141138

142-
# Getting arguments
139+
# Getting the type of activity bout to be analyzed
143140
behaviour <- match.arg(behaviour)
144141
if(behaviour == "sed") {BEHAV <- "SED"; color_fill = c("#D9DBE5", "#A6ADD5", "#6A78C3", "#3F51B5"); auto_text = "sedentary"}
145142
if(behaviour == "pa") {BEHAV <- "PA"; color_fill = c("#EDD3DD", "#F38DB6", "#FA3B87", "#FF0066"); auto_text = "physical activity"}
146143

147-
# Getting correction factor related to the epoch length (reference epoch = 60 s);
144+
# Getting the correction factor related to the epoch length (reference epoch = 60 s);
148145
# bout durations are computed in minutes
149146
cor_factor = 60 / (as.numeric(data[[col_time]][2] - data[[col_time]][1]))
150147

151-
# Summarising bout durations (in minutes) of interest by day
148+
# Getting all the identified bouts of the kind of interest and their respective
149+
# durations (in minutes)
152150
recap_bouts_by_day <-
153151
data %>%
154152
dplyr::group_by(date, new_bout, new_intensity_category) %>%
@@ -166,7 +164,7 @@ recap_bouts_by_day <-
166164
)
167165

168166

169-
# Computing mean daily number of breaks
167+
# Computing the mean of the daily number of breaks
170168
mean_breaks <-
171169
recap_bouts_by_day %>%
172170
dplyr::ungroup(new_bout, new_intensity_category) %>%
@@ -206,19 +204,21 @@ mean_breaks <-
206204
fill = dur_cat
207205
)
208206
) +
209-
geom_rect(aes(
207+
annotate(
208+
geom = "rect",
210209
xmin = hms::as_hms(0),
211210
xmax = hms::as_hms(valid_wear_time_start),
212211
ymin = -Inf,
213-
ymax = Inf),
212+
ymax = Inf,
214213
color = "grey",
215214
fill = "grey"
216215
) +
217-
geom_rect(aes(
216+
annotate(
217+
geom = "rect",
218218
xmin = hms::as_hms(valid_wear_time_end),
219219
xmax = hms::as_hms("23:59:59"),
220220
ymin = -Inf,
221-
ymax = Inf),
221+
ymax = Inf,
222222
color = "grey",
223223
fill = "grey"
224224
) +
@@ -266,7 +266,8 @@ mean_breaks <-
266266
geom_vline(aes(xintercept = 3600*22), linetype = "dotted", color = "grey50") +
267267
geom_vline(aes(xintercept = 3600*23), linetype = "dotted", color = "grey50")
268268

269-
# Summarising bout durations (in minutes) of interest without grouping by day
269+
# Getting all the identified bouts of the kind of interest and their respective
270+
# durations (in minutes) without grouping by day
270271
recap_bouts <-
271272
data %>%
272273
dplyr::group_by(new_bout, new_intensity_category) %>%
@@ -308,7 +309,7 @@ summarised_bouts <-
308309
)
309310

310311

311-
# Fitting cumulated fraction of time vs bout duration
312+
# Fitting cumulated fraction of time vs bout duration relationship
312313
model <- nls(
313314
cum_frac_time ~ duration^x / (duration^x + UBD^x),
314315
data = summarised_bouts,
@@ -333,26 +334,26 @@ max_bout_duration <- max(summarised_bouts$duration)
333334
duration = seq(xmin, max_bout_duration, 0.1)
334335
) %>%
335336
dplyr::mutate(
336-
pred = duration ^ (-alpha) ,
337+
pred = duration ^ (-alpha),
337338
pred = duration ^ (-alpha) / max(pred) * max(summarised_bouts$n, na.rm = TRUE)
338339
)
339340

340341
# Building the graphic
341342
p_alpha <-
342-
ggplot(data = recap_bouts) +
343+
ggplot(data = recap_bouts |> dplyr::ungroup(new_bout)) +
343344
geom_histogram(aes(x = duration, fill = dur_cat), binwidth = xmin) +
344345
scale_fill_manual(values = color_fill) +
345346
labs(x = "Bout duration (min)", y = "n", fill = "Duration (min)") +
346-
geom_line(data = df_pred_alpha, aes(x = duration, y = pred), linewidth = 0.8, color = "grey10") +
347+
geom_line(data = df_pred_alpha, aes(x = duration, y = pred), linewidth = 0.5, color = "grey10") +
347348
annotate("text", x = max_bout_duration/2, y = max(summarised_bouts$n, na.rm = TRUE)/2, label = paste("alpha =", round(alpha, 2)), hjust = 0.5, size = 6, vjust = 0.5) +
348349
theme_bw() +
349350
theme(legend.position = "bottom")
350351

351352
# Building a graphic for MBD
352353
p_MBD <-
353-
ggplot(data = recap_bouts) +
354+
ggplot(data = recap_bouts |> dplyr::ungroup(new_bout)) +
354355
geom_histogram(aes(x = duration, fill = dur_cat), binwidth = xmin) +
355-
geom_segment(aes(x = MBD, xend = MBD, y = 0, yend = max(summarised_bouts$n, na.rm = TRUE)), linetype = "dashed") +
356+
annotate(geom = "segment", x = MBD, xend = MBD, y = 0, yend = max(summarised_bouts$n, na.rm = TRUE), linetype = "dashed") +
356357
scale_fill_manual(values = color_fill) +
357358
labs(x = "Bout duration (min)", y = "n", fill = "Duration (min)") +
358359
geom_segment(
@@ -377,10 +378,10 @@ p_MBD <-
377378
p_UBD <-
378379
ggplot(data = summarised_bouts, aes(x = duration, y = cum_frac_time)) +
379380
geom_point(aes(color = dur_cat), size = 6) +
380-
geom_segment(aes(x = 0, y = 0.5, xend = UBD, yend = 0.5), linetype = "dashed", linewidth = 0.5) +
381-
geom_segment(aes(x = UBD, y = 0.5, xend = UBD, yend = 0), linetype = "dashed", linewidth = 0.5) +
382-
geom_line(data = df_pred_UBD, aes(x = duration, y = pred), linewidth = 0.8, color = "grey10") +
383-
geom_segment(aes(x = max_bout_duration/2, y = 0.4, xend = UBD, yend = 0), arrow = arrow(length = unit(0.02, "npc"))) +
381+
annotate(geom = "segment", x = 0, y = 0.5, xend = UBD, yend = 0.5, linetype = "dashed", linewidth = 0.5) +
382+
annotate(geom = "segment", x = UBD, y = 0.5, xend = UBD, yend = 0, linetype = "dashed", linewidth = 0.5) +
383+
geom_line(data = df_pred_UBD, aes(x = duration, y = pred), linewidth = 0.5, color = "grey10") +
384+
annotate(geom = "segment", x = max_bout_duration/2, y = 0.4, xend = UBD, yend = 0, arrow = arrow(length = unit(0.02, "npc"))) +
384385
annotate("text", x = max_bout_duration/2, y = 0.4, label = paste(" UBD =", round(UBD, 1), "min"), hjust = 0, size = 6, vjust = 0) +
385386
labs(x = "Bout duration (min)", y = paste("Cumulated fraction of total", auto_text, "time"), color = "Duration (min)") +
386387
scale_color_manual(values = color_fill) +
@@ -417,7 +418,7 @@ p_gini <-
417418
geom_ribbon(aes(x = cum_frac_bout, ymin = cum_frac_time, ymax = cum_frac_bout), fill = alpha(color_fill[[2]], 0.3)) +
418419
geom_point(data = summarised_bouts2, aes(color = dur_cat), size = 6) +
419420
geom_segment(x = 0, xend = 1, y = 0, yend = 1, linewidth = 0.3) +
420-
geom_line(linewidth = 0.6) +
421+
geom_line(linewidth = 0.5) +
421422
scale_color_manual(values = color_fill) +
422423
coord_cartesian(xlim = c(0, 1), ylim = c(0, 1)) +
423424
labs(

R/compute_intensity_distri_metrics.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ df_mx <-
154154
M60 = compute_mx(x = .data[[col_axis]], n = 60 * cor_factor),
155155
M30 = compute_mx(x = .data[[col_axis]], n = 30 * cor_factor),
156156
M15 = compute_mx(x = .data[[col_axis]], n = 15 * cor_factor),
157-
M5 = compute_mx(x = .data[[col_axis]], n = 15 * cor_factor)
157+
M5 = compute_mx(x = .data[[col_axis]], n = 5 * cor_factor)
158158
)
159159

160160

R/create_fig_mx_summary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ p <-
126126
axis.text.x = element_text(size = 15),
127127
legend.text = element_text(size = 12),
128128
legend.key.width = unit(1.5,"cm"),
129-
legend.position = c(0.13, 0.07)
129+
legend.position.inside = c(0.13, 0.07)
130130
) +
131131
guides(color = "none", fill = "none")
132132

R/create_fig_pal.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if (language == "en") {
6060
theme(axis.ticks = element_blank(),
6161
axis.text.y = element_blank(),
6262
axis.text.x = element_text(size = 13),
63-
legend.position = c(0.5, 1.4),
63+
legend.position.inside = c(0.5, 1.4),
6464
legend.title = element_text(face = "bold" , size = 10),
6565
legend.text = element_text(face = "bold", size = 17),
6666
legend.background = element_rect(fill = "beige"),
@@ -105,7 +105,7 @@ if (language == "fr") {
105105
theme(axis.ticks = element_blank(),
106106
axis.text.y = element_blank(),
107107
axis.text.x = element_text(size = 13),
108-
legend.position = c(0.5, 1.4),
108+
legend.position.inside = c(0.5, 1.4),
109109
legend.title = element_text(face = "bold" , size = 10),
110110
legend.text = element_text(face = "bold", size = 17),
111111
legend.background = element_rect(fill = "beige"),
@@ -151,7 +151,7 @@ if (language == "de") {
151151
theme(axis.ticks = element_blank(),
152152
axis.text.y = element_blank(),
153153
axis.text.x = element_text(size = 13),
154-
legend.position = c(0.5, 1.4),
154+
legend.position.inside = c(0.5, 1.4),
155155
legend.title = element_text(face = "bold" , size = 10),
156156
legend.text = element_text(face = "bold", size = 17),
157157
legend.background = element_rect(fill = "beige"),

R/do_all_analyses.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#' the package. It is an internal function allowing the computation of the speed of the whole
66
#' analysis process, from the data importation to the final line of the results.
77
#'
8+
#' @param to_epoch A numeric value to set the epoch required to collapse counts
9+
#' in seconds.
10+
#'
811
#' @return
912
#' A dataset (1 row) with all computed metrics.
1013

R/get_ig_results.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ get_ig_results <- function(
5454
df_bins$bin_label <- paste0(round(df_bins$bin_start, 0),"-", round(df_bins$bin_end, 0))
5555

5656
# Correcting the value of the upper bound of the last bin (the value has been arbitrarily set so that it is very high)
57-
df_bins[nrow(df_bins), "bin_end"] <- 50000
57+
df_bins[nrow(df_bins), "bin_end"] <- 1000000
5858

5959
# Correcting the label of the last bin
6060
df_bins[nrow(df_bins), "bin_label"] <- paste0(">", round(df_bins[nrow(df_bins), "bin_start"]-1, 0))

R/mark_wear_time.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ mark_wear_time <- function(
108108
streamFrame = streamFrame
109109
) %>%
110110
dplyr::mutate(
111+
wearing = dplyr::if_else(is.na(wearing), "nw", wearing),
111112
non_wearing_count = dplyr::if_else(wearing == "nw", 1, 0),
112113
wearing_count = dplyr::if_else(wearing == "w", 1, 0)
113114
)
114115

116+
115117
return(df2)
116118

117119
}

0 commit comments

Comments
 (0)