From 763f6da095450d456ea26d86ca21bc22ca1af8a1 Mon Sep 17 00:00:00 2001 From: Ramiro Magno Date: Wed, 22 Nov 2023 15:57:18 +0000 Subject: [PATCH] Update style --- R/dtc_create_iso8601.R | 1 - R/parse_dttm_fmt.R | 33 ++++++++++++++-------------- tests/testthat/test-parse_dttm_fmt.R | 5 ----- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/R/dtc_create_iso8601.R b/R/dtc_create_iso8601.R index 34981d44..9d2908de 100644 --- a/R/dtc_create_iso8601.R +++ b/R/dtc_create_iso8601.R @@ -396,7 +396,6 @@ format_iso8601 <- function(m, .cutoff_2000 = 68L) { #' #' @export create_iso8601 <- function(..., .format, .fmt_c = fmt_cmp(), .na = NULL, .cutoff_2000 = 68L, .check_format = FALSE) { - assert_fmt_c(.fmt_c) dots <- rlang::dots_list(...) diff --git a/R/parse_dttm_fmt.R b/R/parse_dttm_fmt.R index e3e6e26d..eeb1e371 100644 --- a/R/parse_dttm_fmt.R +++ b/R/parse_dttm_fmt.R @@ -151,16 +151,17 @@ fmt_cmp <- function(sec = "S+", mday = "d+", mon = "m+", year = "y+") { - structure(list( - sec = sec, - min = min, - hour = hour, - mday = mday, - mon = mon, - year = year - ), - class = "fmt_c") - + structure( + list( + sec = sec, + min = min, + hour = hour, + mday = mday, + mon = mon, + year = year + ), + class = "fmt_c" + ) } assert_fmt_c <- function(x) { @@ -297,17 +298,16 @@ fmt_dttmc <- len = len, ord = ord ) - } #' @rdname parse_dttm_fmt parse_dttm_fmt_ <- function(fmt, pattern) { - admiraldev::assert_character_scalar(fmt) admiraldev::assert_character_scalar(pattern) - if (identical(nchar(pattern), 0L)) + if (identical(nchar(pattern), 0L)) { rlang::abort("`pattern` must be a literal string of at least one char.") + } match_data <- regexpr(pattern, fmt) match <- reg_matches(fmt, match_data) @@ -378,14 +378,16 @@ parse_dttm_fmt <- function(fmt, patterns = fmt_cmp()) { # Check if patterns have matching overlap, i.e. whether they are not # mutually exclusive (as they should). - if (anyDuplicated(pseq(fmt_dttmc$start, fmt_dttmc$end))) + if (anyDuplicated(pseq(fmt_dttmc$start, fmt_dttmc$end))) { rlang::abort("Patterns in `fmt_c` have overlapping matches.") + } # Get captures' ranks while leaving NA as NA (`rank()` won't do this.) fmt_dttmc$ord <- dplyr::row_number(fmt_dttmc$start) - if (identical(nrow(fmt_dttmc), 0L)) + if (identical(nrow(fmt_dttmc), 0L)) { return(fmt_dttmc()) + } fmt_len <- nchar(fmt) @@ -437,7 +439,6 @@ parse_dttm_fmt <- function(fmt, patterns = fmt_cmp()) { #' #' @keywords internal dttm_fmt_to_regex <- function(fmt, fmt_regex = fmt_rg(), fmt_c = fmt_cmp(), anchored = TRUE) { - tbl_fmt_c <- parse_dttm_fmt(fmt, patterns = fmt_c) fmt_regex <- diff --git a/tests/testthat/test-parse_dttm_fmt.R b/tests/testthat/test-parse_dttm_fmt.R index ed79dae7..1108c569 100644 --- a/tests/testthat/test-parse_dttm_fmt.R +++ b/tests/testthat/test-parse_dttm_fmt.R @@ -1,5 +1,4 @@ test_that("`parse_dttm_fmt_`: empty fmt", { - x <- tibble::tibble( pat = character(), @@ -18,7 +17,6 @@ test_that("`parse_dttm_fmt_`: empty pattern", { }) test_that("`parse_dttm_fmt_`: basic usage", { - fmt1 <- "y m d" fmt2 <- "y-m-d" @@ -58,7 +56,6 @@ test_that("`parse_dttm_fmt_`: basic usage", { }) test_that("`parse_dttm_fmt_`: pattern variations", { - fmt <- "HH:MM:SS" x1 <- @@ -94,7 +91,6 @@ test_that("`parse_dttm_fmt_`: pattern variations", { }) test_that("`parse_dttm_fmt_`: only the first match is returned", { - fmt <- "H M S H" x1 <- @@ -130,7 +126,6 @@ test_that("`parse_dttm_fmt_`: only the first match is returned", { }) test_that("`parse_dttm_fmt`: empty fmt", { - expect_identical(fmt_dttmc(), parse_dttm_fmt("", pattern = "y")) expect_error(parse_dttm_fmt_(character(), pattern = "y")) })