Skip to content

Commit

Permalink
Rename the 'sd' function to 'sdu'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvartan committed Oct 3, 2021
1 parent 0b9d298 commit ec34d83
Show file tree
Hide file tree
Showing 32 changed files with 116 additions and 126 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export(qplot_walk)
export(random_mctq)
export(raw_data)
export(round_time)
export(sd)
export(sd24)
export(sd_overall)
export(sd_week)
export(sdu)
export(shorter_interval)
export(sjl)
export(sjl_rel)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# mctq 0.0.0.9001

## Breaking changes

* The `sd()` function is now named as `sdu()`. That was a tough, but necessary, call. Although we tried to preserve the original authors naming pattern for the MCTQ functions, the name `sd` provokes a dangerous name collision with the widely used `stats::sd` (standard deviation) function. That's why we named it as `sdu`. This is the only exception, all the other `mctq` functions maintain a strong naming resemblance with the original authors naming pattern.

## Added

* @jonkeane was added as a reviewer ('rev').
Expand Down
6 changes: 3 additions & 3 deletions R/ms.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#' use [mctq::so()] to compute it for the standard or shift version.
#' @param sd A `Duration` object corresponding to the __sleep duration__ from a
#' standard, micro, or shift version of the MCTQ questionnaire. You can use
#' [mctq::sd()] to compute it for any MCTQ version.
#' [mctq::sdu()] to compute it for any MCTQ version.
#'
#' @return A `hms` object corresponding to the vectorized sum of `so` and `(sd /
#' 2)` in a circular time frame of 24 hours.
Expand Down Expand Up @@ -193,10 +193,10 @@ ms <- function(so, sd) {
#' questionnaire. You can use [mctq::ms()] to compute it.
#' @param sd_w A `Duration` object corresponding to the __sleep duration on work
#' days__ from a standard, micro, or shift version of the MCTQ questionnaire.
#' You can use [mctq::sd()] to compute it.
#' You can use [mctq::sdu()] to compute it.
#' @param sd_f A `Duration` object corresponding to the __sleep duration on
#' work-free days__ from a standard, micro, or shift version of the MCTQ
#' questionnaire. You can use [mctq::sd()] to compute it.
#' questionnaire. You can use [mctq::sdu()] to compute it.
#' @param sd_week A `Duration` object corresponding to the __average weekly
#' sleep duration__ from a standard or micro version of the MCTQ questionnaire
#' (you can use [mctq::sd_week()] to compute it) __or__ the __overall sleep
Expand Down
31 changes: 19 additions & 12 deletions R/sd.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
#'
#' `r lifecycle::badge("maturing")`
#'
#' `sd()` computes the __sleep duration__ for standard, micro, and shift
#' `sdu()` computes the __sleep duration__ for standard, micro, and shift
#' versions of the Munich Chronotype Questionnaire (MCTQ).
#'
#' Please note that, although we tried to preserve the original authors naming
#' pattern for the MCTQ functions, the name `sd` provokes a dangerous name
#' collision with the widely used [stats::sd] (standard deviation) function.
#' That's why we named it as `sdu`. This is the only exception, all the other
#' `mctq` functions maintain a strong naming resemblance with the original
#' authors naming pattern.
#'
#' @section Guidelines:
#'
#' Roenneberg, Allebrandt, Merrow, & Vetter (2012), Ghotbi et al. (2020), Juda,
#' Vetter, & Roenneberg (2013), and The Worldwide Experimental Platform (n.d.)
#' guidelines for `sd()` (\eqn{SD}) computation are as follows.
#' guidelines for `sdu()` (\eqn{SD}) computation are as follows.
#'
#' ## Notes
#'
Expand Down Expand Up @@ -71,26 +78,26 @@
#'
#' so <- hms::parse_hm("23:00")
#' se <- hms::parse_hm("08:00")
#' sd(so, se)
#' sdu(so, se)
#' #> [1] "32400s (~9 hours)" # Expected
#'
#' so <- hms::parse_hm("02:00")
#' se <- hms::parse_hm("12:30")
#' sd(so, se)
#' sdu(so, se)
#' #> [1] "37800s (~10.5 hours)" # Expected
#'
#' so <- hms::parse_hm("03:15")
#' se <- hms::as_hms(NA)
#' sd(so, se)
#' sdu(so, se)
#' #> [1] NA # Expected
#'
#' ## Vector example
#'
#' so <- c(hms::parse_hm("04:12"), hms::parse_hm("21:20"))
#' se <- c(hms::parse_hm("14:30"), hms::parse_hm("03:45"))
#' sd(so, se)
#' sdu(so, se)
#' #> [1] "37080s (~10.3 hours)" "23100s (~6.42 hours)" # Expected
sd <- function(so, se) {
sdu <- function(so, se) {
checkmate::assert_class(so, "hms")
checkmate::assert_class(se, "hms")
assert_identical(so, se, type = "length")
Expand Down Expand Up @@ -229,7 +236,7 @@ napd <- function(napo, nape) {
#' morning shift; \eqn{E} = evening shift; \eqn{N} = night shift.
#'
#' @param sd A `Duration` object corresponding to the __sleep duration__ from
#' the shift version of the MCTQ questionnaire. You can use [mctq::sd()] to
#' the shift version of the MCTQ questionnaire. You can use [mctq::sdu()] to
#' compute it.
#' @param napd A `Duration` object corresponding to the __nap duration__ from
#' the shift version of the MCTQ questionnaire. You can use [mctq::napd()] to
Expand Down Expand Up @@ -343,10 +350,10 @@ sd24 <- function(sd, napd, nap) {
#'
#' @param sd_w A `Duration` object corresponding to the __sleep duration on
#' workdays__ from a standard or micro version of the MCTQ questionnaire. You
#' can use [mctq::sd()] to compute it.
#' can use [mctq::sdu()] to compute it.
#' @param sd_f A `Duration` object corresponding to the __sleep duration on
#' work-free days__ from a standard or micro version of the MCTQ
#' questionnaire. You can use [mctq::sd()] to compute it.
#' questionnaire. You can use [mctq::sdu()] to compute it.
#'
#' @return A `Duration` object corresponding to the vectorized weighted mean of
#' `sd_w` and `sd_f` with `wd` and `fd(wd)` as weights.
Expand Down Expand Up @@ -486,10 +493,10 @@ sd_week <- function(sd_w, sd_f, wd) {
#'
#' @param sd_w A `Duration` object corresponding to the __sleep duration between
#' two days in a particular shift__ from a shift version of the MCTQ
#' questionnaire. You can use [mctq::sd()] to compute it.
#' questionnaire. You can use [mctq::sdu()] to compute it.
#' @param sd_f A `Duration` object corresponding to the __sleep duration between
#' two free days after a particular shift__ from a shift version of the MCTQ
#' questionnaire. You can use [mctq::sd()] to compute it.
#' questionnaire. You can use [mctq::sdu()] to compute it.
#' @param n_w An [integerish][checkmate::test_integerish()] `numeric` object or
#' an `integer` object corresponding to the __number of days worked in a
#' particular shift within a shift cycle__ from a shift version of the MCTQ
Expand Down
4 changes: 2 additions & 2 deletions R/sjl.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ sjl_weighted <- function(sjl, n_w) {
sjl <- lapply(sjl, abs)
n_w <- lapply(n_w, as.integer)

foo <- function(x, y) {
reduce <- function(x, y) {
out <- Reduce("*", list(x, y))
lubridate::as.duration(out)
}

sjl <- mapply(foo, n_w, sjl, SIMPLIFY = FALSE)
sjl <- mapply(reduce, n_w, sjl, SIMPLIFY = FALSE)
sjl <- Reduce("+", sjl)
n_w <- Reduce("+", n_w)

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Note that the `mctq` functions uses a similar naming scheme to that used in the
* `fd()`: compute MCTQ work-free days
* `so()`: compute MCTQ local time of sleep onset
* `gu()`: compute MCTQ local time of getting out of bed
* `sd()`: compute MCTQ sleep duration
* `sdu()`: compute MCTQ sleep duration
* `tbt()`: compute MCTQ total time in bed
* `ms()`: compute MCTQ local time of mid-sleep
* `napd()`: compute MCTQ nap duration (only for MCTQ Shift)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ computation necessary.
- `fd()`: compute MCTQ work-free days
- `so()`: compute MCTQ local time of sleep onset
- `gu()`: compute MCTQ local time of getting out of bed
- `sd()`: compute MCTQ sleep duration
- `sdu()`: compute MCTQ sleep duration
- `tbt()`: compute MCTQ total time in bed
- `ms()`: compute MCTQ local time of mid-sleep
- `napd()`: compute MCTQ nap duration (only for MCTQ Shift)
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ reference:
- fd
- so
- gu
- sd
- sdu
- tbt
- ms
- napd
Expand Down
38 changes: 9 additions & 29 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.1.0 (2021-05-18)",
"runtimePlatform": "R version 4.1.1 (2021-08-10)",
"author": [
{
"@type": "Person",
Expand Down Expand Up @@ -85,35 +85,11 @@
},
"sameAs": "https://CRAN.R-project.org/package=covr"
},
{
"@type": "SoftwareApplication",
"identifier": "crayon",
"name": "crayon",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=crayon"
},
{
"@type": "SoftwareApplication",
"identifier": "datasets",
"name": "datasets"
},
{
"@type": "SoftwareApplication",
"identifier": "emojifont",
"name": "emojifont",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=emojifont"
},
{
"@type": "SoftwareApplication",
"identifier": "ggplot2",
Expand Down Expand Up @@ -238,6 +214,7 @@
"@type": "SoftwareApplication",
"identifier": "checkmate",
"name": "checkmate",
"version": ">= 2.0.0",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand All @@ -250,6 +227,7 @@
"@type": "SoftwareApplication",
"identifier": "cli",
"name": "cli",
"version": ">= 3.0.1",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand All @@ -262,7 +240,7 @@
"@type": "SoftwareApplication",
"identifier": "dplyr",
"name": "dplyr",
"version": ">= 0.2",
"version": ">= 1.0.7",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand All @@ -275,6 +253,7 @@
"@type": "SoftwareApplication",
"identifier": "hms",
"name": "hms",
"version": ">= 1.1.0",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand All @@ -287,6 +266,7 @@
"@type": "SoftwareApplication",
"identifier": "lifecycle",
"name": "lifecycle",
"version": ">= 1.0.0",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand All @@ -299,7 +279,7 @@
"@type": "SoftwareApplication",
"identifier": "lubridate",
"name": "lubridate",
"version": ">= 1.7.9",
"version": ">= 1.7.10",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand All @@ -310,8 +290,8 @@
}
],
"releaseNotes": "https://github.com/gipso/mctq/blob/master/NEWS.md",
"fileSize": "0KB",
"contIntegration": "https://codecov.io/gh/gipso/mctq",
"fileSize": "752.841KB",
"contIntegration": ["https://github.com/gipso/mctq/actions", "https://codecov.io/gh/gipso/mctq"],
"developmentStatus": ["https://www.repostatus.org/#active", "https://www.tidyverse.org/lifecycle/#maturing"],
"keywords": [
"chronobiology",
Expand Down
8 changes: 3 additions & 5 deletions data-raw/micro_mctq.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Source the file before running the functions
# Don't forget to uncomment the `library` functions below

library(magrittr)

# library(checkmate)
# library(dplyr)
# library(hms)
Expand Down Expand Up @@ -466,7 +464,7 @@ validate_micro_mctq <- function(write = FALSE) {

micro_mctq <- micro_mctq %>%
dplyr::mutate(
sd_i = mctq::sd(!!as.symbol(so_i), !!as.symbol(se_i)),
sd_i = mctq::sdu(!!as.symbol(so_i), !!as.symbol(se_i)),
dummy = dplyr::case_when(
sd_i < lubridate::dhours(2) |
sd_i > lubridate::dhours(18) ~ TRUE,
Expand Down Expand Up @@ -548,10 +546,10 @@ analyze_micro_mctq <- function(write = FALSE, round = TRUE, hms = FALSE) {
dplyr::mutate(
fd = fd(wd),

sd_w = sd(so_w, se_w),
sd_w = sdu(so_w, se_w),
msw = ms(so_w, sd_w),

sd_f = sd(so_f, se_f),
sd_f = sdu(so_f, se_f),
msf = ms(so_f, sd_f),

sd_week = sd_week(sd_w, sd_f, wd),
Expand Down
2 changes: 0 additions & 2 deletions data-raw/random_mctq.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Source the file before running the functions
# Don't forget to uncomment the `library` functions below

library(magrittr)

# library(checkmate)
# library(cli)
# library(glue)
Expand Down
6 changes: 2 additions & 4 deletions data-raw/shift_mctq.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Source the file before running the functions
# Don't forget to uncomment the `library` functions below

library(magrittr)

# library(checkmate)
# library(dplyr)
# library(hms)
Expand Down Expand Up @@ -1320,7 +1318,7 @@ validate_shift_mctq <- function(write = FALSE) {
test <- shift_mctq %>%
dplyr::mutate(
so_i = mctq::so(!!as.symbol(sprep_i), !!as.symbol(slat_i)),
sd_i = mctq::sd(so_i, !!as.symbol(se_i)),
sd_i = mctq::sdu(so_i, !!as.symbol(se_i)),
dummy = dplyr::case_when(
sd_i < lubridate::dhours(2) |
sd_i > lubridate::dhours(18) ~ TRUE,
Expand Down Expand Up @@ -1426,7 +1424,7 @@ analyze_shift_mctq <- function(write = FALSE, round = TRUE, hms = FALSE) {
gu(!!as.symbol(paste0("se", i)),
!!as.symbol(paste0("tgu", i))),
!!as.symbol(paste0("sd", i)) :=
sd(!!as.symbol(paste0("so", i)),
sdu(!!as.symbol(paste0("so", i)),
!!as.symbol(paste0("se", i))),
!!as.symbol(paste0("tbt", i)) :=
tbt(!!as.symbol(paste0("bt", i)),
Expand Down
8 changes: 3 additions & 5 deletions data-raw/std_mctq.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Source the file before running the functions
# Don't forget to uncomment the `library` functions below

library(magrittr)

# library(checkmate)
# library(dplyr)
# library(hms)
Expand Down Expand Up @@ -794,7 +792,7 @@ validate_std_mctq <- function(write = FALSE) {
test <- std_mctq %>%
dplyr::mutate(
so_i = mctq::so(!!as.symbol(sprep_i), !!as.symbol(slat_i)),
sd_i = mctq::sd(so_i, !!as.symbol(se_i)),
sd_i = mctq::sdu(so_i, !!as.symbol(se_i)),
dummy = dplyr::case_when(
sd_i < lubridate::dhours(2) |
sd_i > lubridate::dhours(18) ~ TRUE,
Expand Down Expand Up @@ -894,13 +892,13 @@ analyze_std_mctq <- function(write = FALSE, round = TRUE, hms = FALSE) {
fd = fd(wd),
so_w = so(sprep_w, slat_w),
gu_w = gu(se_w, si_w),
sd_w = sd(so_w, se_w),
sd_w = sdu(so_w, se_w),
tbt_w = tbt(bt_w, gu_w),
msw = ms(so_w, sd_w),

so_f = so(sprep_f, slat_f),
gu_f = gu(se_f, si_f),
sd_f = sd(so_f, se_f),
sd_f = sdu(so_f, se_f),
tbt_f = tbt(bt_f, gu_f),
msf = ms(so_f, sd_f),

Expand Down
2 changes: 0 additions & 2 deletions data-raw/vignette_mctq.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Source the file before running the function
# Don't forget to uncomment the `library` functions below

library(magrittr)

# library(checkmate)
# library(dplyr)
# library(mctq)
Expand Down
Loading

0 comments on commit ec34d83

Please sign in to comment.