Skip to content

Commit

Permalink
Rename 'ms()' to 'msl()'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvartan committed Oct 11, 2021
1 parent aee6bc0 commit 1de1e2c
Show file tree
Hide file tree
Showing 29 changed files with 212 additions and 198 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export(fd)
export(gu)
export(le_week)
export(longer_interval)
export(ms)
export(msf_sc)
export(msl)
export(napd)
export(pretty_mctq)
export(qplot_walk)
Expand Down
13 changes: 7 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@
## Changed

* The DESCRIPTION file now requires a lubridate version `>= 1.7.9`. `vctrs` support was added in this version, fixing some issues related to rounding `Duration`, `Period`, and `Interval` objects. Click [here](https://github.com/tidyverse/lubridate/pull/871) to learn more.
* The DESCRIPTION file now requires a dplyr version `>= 0.2`. That's when the `dplyr` start to import the pipe operator. Click [here](https://github.com/tidyverse/dplyr/blob/master/NEWS.md#piping) to learn more.
* To avoid any unknown compatibility issues, all packages on imports now requires the latest version of them at the moment of this release.
* The DESCRIPTION file now requires a dplyr version `>= 0.2`. That's when the `dplyr` starts to import the pipe operator. Click [here](https://github.com/tidyverse/dplyr/blob/master/NEWS.md#piping) to learn more.
* To avoid any unknown compatibility issues, all packages on imports now require the latest version of them at the moment of this release.
* `convert()` and all `convert_*()` functions were removed. See a dedicated note about this below.
* `round_time()` is now a S3 generic.
* `shortest_interval()` was renamed to `shorter_interval()`.
* `shorter_interval()` and `longer_interval()` now return only `Interval` objects.
* `assign_date()` now return only `Interval` objects.
* `sum_time()` now have different arguments and was divided in two functions: `sum_time()` (for non-vectorized sums) and `vct_sum_time()` (for vectorized sums).
* The `sd()` function was renamed to `sdu()`. See a dedicated note about this below.
* Several functions were optimized.
* The `ms()` function was renamed to `msl()`. See a dedicated note about this below.

## Fixed

* Several typos were fixed in the documentation.
* Several functions were optimized.

## Note about removing `convert()`

`convert()` was created considering the user experience (sleep and chronobiology scientists). Since most of them don't have much experience with R and that time can have different types of representations (e.g., decimal hours, radian), `convert()` helped by trying to transpose those difficulties, posing as an "universal translator" (🖖).

After much thought and consideration, we believe that the `convert()` feature may be out of the `mctq` scope. It can maybe be part of another package (a `lubritime` package perhaps? 😄). Other `mctq` tools, like `shorter_interval()` and `sum_time()`, could also be a part of that package (but are really necessary in `mctq` for the time being). Hence, we decided to remove `convert()` and to instruct the user to check the [lubridate](https://lubridate.tidyverse.org/) and [hms](https://hms.tidyverse.org/) packages for parsing/conversion.
After much thought and consideration, we believe that the `convert()` feature may be out of the `mctq` scope. It can maybe be part of another package (a `lubritime` package perhaps? 😄). Other `mctq` tools, like `shorter_interval()` and `sum_time()`, could also be a part of that package (but are necessary in `mctq` for the time being). Hence, we decided to remove `convert()` and to instruct the user to check the [lubridate](https://lubridate.tidyverse.org/) and [hms](https://hms.tidyverse.org/) packages for parsing/conversion.

## Note about renaming `sd()`
## Note about renaming `sd()` and `ms()`

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.
That was a tough, but necessary, call. Although we tried to preserve the original author's naming pattern for the MCTQ functions, the name `sd` provokes a dangerous name collision with the widely used `stats::sd` function (standard deviation) and the name `ms` provokes a name collision with `lubridate::ms()` function (a function for parsing minutes and seconds components). That's why we decided to renamed them. `sdu()` and `msl()` the only exceptions, all the other `mctq` functions maintain a strong naming resemblance with the original author's naming pattern.


# mctq 0.0.0.9000
Expand Down
23 changes: 15 additions & 8 deletions R/ms.R → R/msl.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
#'
#' `r lifecycle::badge("maturing")`
#'
#' `ms()` computes the __local time of mid-sleep__ for standard, micro, and
#' `msl()` computes the __local time of mid-sleep__ 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 `ms` provokes a dangerous name
#' collision with the [lubridate::ms()] function (a function for parsing minutes
#' and seconds components). That's why we named it `msl`. `msl()` and [sdu()]
#' are the only exceptions, 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 `ms()` (\eqn{MSW} or \eqn{MSF}) computation are as follows.
#' guidelines for `msl()` (\eqn{MSW} or \eqn{MSF}) computation are as follows.
#'
#' ## Notes
#'
Expand Down Expand Up @@ -72,27 +79,27 @@
#'
#' so <- hms::parse_hm("23:30")
#' sd <- lubridate::dhours(8)
#' ms(so, sd)
#' msl(so, sd)
#' #> 03:30:00 # Expected
#'
#' so <- hms::parse_hm("01:00")
#' sd <- lubridate::dhours(10)
#' ms(so, sd)
#' msl(so, sd)
#' #> 06:00:00 # Expected
#'
#' so <- hms::as_hms(NA)
#' sd <- lubridate::dhours(7.5)
#' ms(so, sd)
#' msl(so, sd)
#' #> NA # Expected
#'
#' ## Vector example
#'
#' so <- c(hms::parse_hm("00:10"), hms::parse_hm("01:15"))
#' sd <- c(lubridate::dhours(9.25), lubridate::dhours(5.45))
#' ms(so, sd)
#' msl(so, sd)
#' #> [1] 04:47:30 # Expected
#' #> [1] 03:58:30 # Expected
ms <- function(so, sd) {
msl <- function(so, sd) {
checkmate::assert_class(so, "hms")
assert_duration(sd)
assert_identical(so, sd, type = "length")
Expand Down Expand Up @@ -190,7 +197,7 @@ ms <- function(so, sd) {
#'
#' @param msf A `hms` object corresponding to the __local time of mid-sleep on
#' work-free days__ from a standard, micro, or shift version of the MCTQ
#' questionnaire. You can use [mctq::ms()] to compute it.
#' questionnaire. You can use [mctq::msl()] 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::sdu()] to compute it.
Expand Down
10 changes: 5 additions & 5 deletions R/sd.R → R/sdu.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#' `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
#' 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.
#' collision with the widely used [stats::sd()] function (standard deviation).
#' That's why we named it `sdu`. `sdu()` and [msl()] are the only exceptions,
#' all the other `mctq` functions maintain a strong naming resemblance with the
#' original authors' naming pattern.
#'
#' @section Guidelines:
#'
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Note that the `mctq` functions uses a similar naming pattern to that used in the
* `gu()`: compute MCTQ local time of getting out of bed
* `sdu()`: compute MCTQ sleep duration
* `tbt()`: compute MCTQ total time in bed
* `ms()`: compute MCTQ local time of mid-sleep
* `msl()`: compute MCTQ local time of mid-sleep
* `napd()`: compute MCTQ nap duration (only for MCTQ Shift)
* `sd24()`: compute MCTQ 24 hours sleep 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 @@ -126,7 +126,7 @@ computation necessary.
- `gu()`: compute MCTQ local time of getting out of bed
- `sdu()`: compute MCTQ sleep duration
- `tbt()`: compute MCTQ total time in bed
- `ms()`: compute MCTQ local time of mid-sleep
- `msl()`: compute MCTQ local time of mid-sleep
- `napd()`: compute MCTQ nap duration (only for MCTQ Shift)
- `sd24()`: compute MCTQ 24 hours sleep 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 @@ -22,7 +22,7 @@ reference:
- gu
- sdu
- tbt
- ms
- msl
- napd
- sd24
- sd_week
Expand Down
4 changes: 2 additions & 2 deletions data-raw/micro_mctq.R
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,10 @@ analyze_micro_mctq <- function(write = FALSE, round = TRUE, hms = FALSE) {
fd = fd(wd),

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

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

sd_week = sd_week(sd_w, sd_f, wd),
msf_sc = msf_sc(msf, sd_w, sd_f, sd_week, rep(FALSE, length(id))),
Expand Down
2 changes: 1 addition & 1 deletion data-raw/shift_mctq.R
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ analyze_shift_mctq <- function(write = FALSE, round = TRUE, hms = FALSE) {
tbt(!!as.symbol(paste0("bt", i)),
!!as.symbol(paste0("gu", i))),
!!as.symbol(ms) :=
ms(!!as.symbol(paste0("so", i)),
msl(!!as.symbol(paste0("so", i)),
!!as.symbol(paste0("sd", i))),
!!as.symbol(paste0("napd", i)) :=
napd(!!as.symbol(paste0("napo", i)),
Expand Down
4 changes: 2 additions & 2 deletions data-raw/std_mctq.R
Original file line number Diff line number Diff line change
Expand Up @@ -927,13 +927,13 @@ analyze_std_mctq <- function(write = FALSE, round = TRUE, hms = FALSE) {
gu_w = gu(se_w, si_w),
sd_w = sdu(so_w, se_w),
tbt_w = tbt(bt_w, gu_w),
msw = ms(so_w, sd_w),
msw = msl(so_w, sd_w),

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

sd_week = sd_week(sd_w, sd_f, wd),
msf_sc = msf_sc(msf, sd_w, sd_f, sd_week, alarm_f),
Expand Down
2 changes: 1 addition & 1 deletion man/fd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gu.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/le_week.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/msf_sc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 17 additions & 10 deletions man/ms.Rd → man/msl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/napd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sd24.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sd_overall.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sd_week.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1de1e2c

Please sign in to comment.