Skip to content

Commit

Permalink
Remove 'convert()'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvartan committed Oct 11, 2021
1 parent 394733b commit aee6bc0
Show file tree
Hide file tree
Showing 56 changed files with 416 additions and 2,786 deletions.
16 changes: 0 additions & 16 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ S3method(clock_roll,Duration)
S3method(clock_roll,Period)
S3method(clock_roll,difftime)
S3method(clock_roll,hms)
S3method(convert,Date)
S3method(convert,Duration)
S3method(convert,Interval)
S3method(convert,POSIXt)
S3method(convert,Period)
S3method(convert,character)
S3method(convert,data.frame)
S3method(convert,difftime)
S3method(convert,hms)
S3method(convert,numeric)
S3method(na_as,Date)
S3method(na_as,Duration)
S3method(na_as,POSIXct)
Expand All @@ -30,12 +20,6 @@ S3method(round_time,difftime)
S3method(round_time,hms)
export(assign_date)
export(chronotype)
export(convert)
export(convert_pt)
export(convert_pu)
export(convert_tu)
export(convert_ut)
export(convert_uu)
export(fd)
export(gu)
export(le_week)
Expand Down
14 changes: 13 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@
* 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.
* `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()`. 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.
* The `sd()` function was renamed to `sdu()`. See a dedicated note about this below.
* Several functions were optimized.

## Fixed

* Several typos were fixed in the documentation.

## 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.

## Note about renaming `sd()`

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.


# mctq 0.0.0.9000

Expand Down
19 changes: 13 additions & 6 deletions R/assign_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#' ## Class requirements
#'
#' The `mctq` package works with a set of object classes specially created to
#' hold time values. These classes can be found in the [hms][hms::hms-package]
#' and [lubridate][lubridate::lubridate-package] package. If your data do not
#' conform to the object classes required, you can use the `mctq`
#' [mctq::convert()] function to convert it.
#' hold time values. These classes can be found in the
#' [lubridate][lubridate::lubridate-package] and [hms][hms::hms-package]
#' packages. Please refer to those package documentations to learn more about
#' them.
#'
#' ## `ambiguity` argument
#'
Expand Down Expand Up @@ -119,8 +119,15 @@ assign_date <- function(start, end, ambiguity = 0) {
lower = 0, upper = 86400)
checkmate::assert_choice(ambiguity, c(0, 24 , NA))

start <- flat_posixt(convert(start, "posixct", quiet = TRUE))
end <- flat_posixt(convert(end, "posixct", quiet = TRUE))
start <- start %>%
hms::as_hms() %>%
as.POSIXct() %>%
flat_posixt()

end <- end %>%
hms::as_hms() %>%
as.POSIXct() %>%
flat_posixt()

out <- dplyr::case_when(
is.na(start) | is.na(end) ~ lubridate::as.interval(NA),
Expand Down
Loading

0 comments on commit aee6bc0

Please sign in to comment.