diff --git a/DESCRIPTION b/DESCRIPTION index 01e01a2a..b9654707 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -59,4 +59,4 @@ Config/Needs/website: cynkra/cynkratemplate Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.3.9000 +Config/roxygen2/version: 8.1.0.9000 diff --git a/NAMESPACE b/NAMESPACE index 196dde10..1411ee7a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -554,9 +554,19 @@ export(opts_yearqtr) export(opts_zoo) export(opts_zooreg) import(rlang) -importFrom(grDevices,dev.off) -importFrom(grDevices,pdf) +importFrom(grDevices, + dev.off, + pdf +) importFrom(methods,getSlots) importFrom(stats,setNames) +importFrom(utils, + capture.output, + getFromNamespace, + head, + methods, + packageDescription, + tail +) useDynLib("") useDynLib(constructive) diff --git a/tests/testthat/_snaps/s3-POSIXct.new.md b/tests/testthat/_snaps/s3-POSIXct.new.md new file mode 100644 index 00000000..201ca1c4 --- /dev/null +++ b/tests/testthat/_snaps/s3-POSIXct.new.md @@ -0,0 +1,82 @@ +# POSIXct post (incl) 4.3 + + Code + construct(.leap.seconds[1:4]) + Output + as.POSIXct(c("1972-07-01", "1973-01-01", "1974-01-01", "1975-01-01"), tz = "GMT") + Code + construct(sys_time_1970) + Output + as.POSIXct("1970-01-01") |> + structure(tzone = NULL) + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "UTC")) + Output + as.POSIXct("2022-01-01 01:00:00", tz = "UTC") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "UTC"), opts_POSIXct( + ".POSIXct")) + Output + .POSIXct(1640998800, tz = "UTC") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "UTC"), opts_POSIXct( + "as_datetime")) + Output + lubridate::as_datetime("2022-01-01 01:00:00") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "CET"), opts_POSIXct( + "as_datetime")) + Message + {constructive} couldn't create code that reproduces perfectly the input + i Call `construct_issues()` to inspect the last issues + Output + lubridate::as_datetime("2022-01-01 01:00:00", tz = "CET") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "UTC"), opts_POSIXct( + "as.POSIXct")) + Output + as.POSIXct("2022-01-01 01:00:00", tz = "UTC") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "UTC"), opts_POSIXct( + "as.POSIXct.numeric")) + Output + as.POSIXct(1640998800, tz = "UTC", origin = "1970-01-01") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "CET"), opts_POSIXct( + "as.POSIXct.numeric", origin = "2000-01-01")) + Output + as.POSIXct(694314000, tz = "CET", origin = "2000-01-01") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "UTC"), opts_POSIXct( + "as_datetime.numeric")) + Output + lubridate::as_datetime(1640998800) + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "CET"), opts_POSIXct( + "as_datetime.numeric", origin = "2000-01-01")) + Output + lubridate::as_datetime(694314000, tz = "CET", origin = "2000-01-01") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "CET"), opts_POSIXct("next")) + Output + 1640998800 |> + structure(class = c("POSIXct", "POSIXt"), tzone = "CET") + Code + construct(as.POSIXct("2022-01-01 01:00:00", tz = "CET"), opts_POSIXct("atomic")) + Output + 1640998800 |> + structure(class = c("POSIXct", "POSIXt"), tzone = "CET") + Code + construct(as.POSIXct("2022-01-01 01:00:00.1", tz = "GMT")) + Output + as.POSIXct("2022-01-01 01:00:00.1", tz = "GMT") + Code + construct(as.POSIXct(c("2022-01-01 01:00:00.1", NA), tz = "GMT")) + Output + as.POSIXct(c("2022-01-01 01:00:00.1", NA), tz = "GMT") + Code + construct(as.POSIXct(c("2024-07-22 13:25:22.868974", + "2024-07-22 13:25:22.868976"), tz = "UTC")) + Output + as.POSIXct(c("2024-07-22 13:25:22.868974", "2024-07-22 13:25:22.868976"), tz = "UTC") + diff --git a/tests/testthat/_snaps/s3-POSIXlt.new.md b/tests/testthat/_snaps/s3-POSIXlt.new.md new file mode 100644 index 00000000..89411b80 --- /dev/null +++ b/tests/testthat/_snaps/s3-POSIXlt.new.md @@ -0,0 +1,114 @@ +# POSIXlt-all-versions + + Code + construct(as.POSIXlt(.leap.seconds[1:4])) + Output + as.POSIXlt(c("1972-07-01", "1973-01-01", "1974-01-01", "1975-01-01"), tz = "GMT") + Code + construct(as.POSIXlt(.leap.seconds[1:4])) + Output + as.POSIXlt(c("1972-07-01", "1973-01-01", "1974-01-01", "1975-01-01"), tz = "GMT") + Code + construct(as.POSIXlt(sys_time_1970)) + Output + as.POSIXlt("1970-01-01", tz = "UTC") + Code + construct(as.POSIXlt("2022-01-01 01:00:00", tz = "UTC")) + Output + as.POSIXlt("2022-01-01 01:00:00", tz = "UTC") + Code + construct(as.POSIXlt("2022-01-01 01:00:00.1", tz = "GMT")) + Output + as.POSIXlt("2022-01-01 01:00:00.1", tz = "GMT") + Code + construct(as.POSIXlt(c("2022-01-01 01:00:00.1", NA), tz = "GMT")) + Output + as.POSIXlt(c("2022-01-01 01:00:00.1", NA), tz = "GMT") + Code + construct(as.POSIXlt(c("2024-07-22 13:25:22.868974", + "2024-07-22 13:25:22.868976"), tz = "UTC")) + Output + as.POSIXlt(c("2024-07-22 13:25:22.868974", "2024-07-22 13:25:22.868976"), tz = "UTC") + +# POSIXlt-from-4.3 + + Code + construct(as.POSIXlt(.leap.seconds[1:4]), opts_POSIXlt("next")) + Output + list( + sec = numeric(4), + min = integer(4), + hour = integer(4), + mday = rep(1L, 4L), + mon = c(6L, 0L, 0L, 0L), + year = 72:75, + wday = c(6L, 1L, 2L, 3L), + yday = c(182L, 0L, 0L, 0L), + isdst = integer(4), + zone = rep("GMT", 4L), + gmtoff = integer(4) + ) |> + structure(class = c("POSIXlt", "POSIXt"), tzone = "GMT", balanced = TRUE) + Code + construct(as.POSIXlt(.leap.seconds[1:4]), opts_POSIXlt("list")) + Output + list( + sec = numeric(4), + min = integer(4), + hour = integer(4), + mday = rep(1L, 4L), + mon = c(6L, 0L, 0L, 0L), + year = 72:75, + wday = c(6L, 1L, 2L, 3L), + yday = c(182L, 0L, 0L, 0L), + isdst = integer(4), + zone = rep("GMT", 4L), + gmtoff = integer(4) + ) |> + structure(class = c("POSIXlt", "POSIXt"), tzone = "GMT", balanced = TRUE) + +--- + + Code + construct(as.POSIXlt(.leap.seconds[1:4])) + Output + as.POSIXlt(c("1972-07-01", "1973-01-01", "1974-01-01", "1975-01-01"), tz = "GMT") + Code + construct(as.POSIXlt(sys_time_1970)) + Output + as.POSIXlt(as.POSIXct("1970-01-01", tz = "CET")) + Code + construct(as.POSIXlt(.leap.seconds[1:4]), opts_POSIXlt("next")) + Output + list( + sec = numeric(4), + min = integer(4), + hour = integer(4), + mday = rep(1L, 4L), + mon = c(6L, 0L, 0L, 0L), + year = 72:75, + wday = c(6L, 1L, 2L, 3L), + yday = c(182L, 0L, 0L, 0L), + isdst = integer(4), + zone = rep("GMT", 4L), + gmtoff = integer(4) + ) |> + structure(class = c("POSIXlt", "POSIXt"), tzone = "GMT", balanced = TRUE) + Code + construct(as.POSIXlt(.leap.seconds[1:4]), opts_POSIXlt("list")) + Output + list( + sec = numeric(4), + min = integer(4), + hour = integer(4), + mday = rep(1L, 4L), + mon = c(6L, 0L, 0L, 0L), + year = 72:75, + wday = c(6L, 1L, 2L, 3L), + yday = c(182L, 0L, 0L, 0L), + isdst = integer(4), + zone = rep("GMT", 4L), + gmtoff = integer(4) + ) |> + structure(class = c("POSIXlt", "POSIXt"), tzone = "GMT", balanced = TRUE) + diff --git a/tests/testthat/_snaps/s3-integer64.new.md b/tests/testthat/_snaps/s3-integer64.new.md new file mode 100644 index 00000000..fc678a06 --- /dev/null +++ b/tests/testthat/_snaps/s3-integer64.new.md @@ -0,0 +1,10 @@ +# integer64 + + Code + construct(bit64::as.integer64(c("-1000", "NA", "100000"))) + Condition + Warning in `as.integer64.character()`: + NAs introduced by coercion to integer64 range + Output + bit64::as.integer64(c("-1000", "NA", "100000")) + diff --git a/tests/testthat/_snaps/s3-tbl_df.new.md b/tests/testthat/_snaps/s3-tbl_df.new.md new file mode 100644 index 00000000..f15a0e7f --- /dev/null +++ b/tests/testthat/_snaps/s3-tbl_df.new.md @@ -0,0 +1,140 @@ +# tbl_df + + Code + construct(dplyr::band_members) + Output + tibble::tibble(name = c("Mick", "John", "Paul"), band = c("Stones", "Beatles", "Beatles")) + Code + construct(dplyr::band_members, opts_tbl_df("next")) + Output + data.frame(name = c("Mick", "John", "Paul"), band = c("Stones", "Beatles", "Beatles")) |> + structure(class = c("tbl_df", "tbl", "data.frame")) + Code + construct(dplyr::band_members, opts_tbl_df("next"), opts_data.frame("next")) + Output + list(name = c("Mick", "John", "Paul"), band = c("Stones", "Beatles", "Beatles")) |> + structure(class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -3L)) + Code + construct(dplyr::band_members, opts_tbl_df(constructor = "tribble")) + Output + tibble::tribble( + ~name, ~band, + "Mick", "Stones", + "John", "Beatles", + "Paul", "Beatles", + ) + Code + construct(dplyr::band_members, opts_tbl_df(constructor = "tribble", justify = "right")) + Output + tibble::tribble( + ~name, ~band, + "Mick", "Stones", + "John", "Beatles", + "Paul", "Beatles", + ) + Code + construct(tibble::tibble(a = as.Date("2001-01-01")), opts_tbl_df("tribble")) + Output + tibble::tribble( + ~a, + as.Date("2001-01-01"), + ) + Code + construct(dplyr::group_by(dplyr::band_members, band)) + Output + tibble::tibble(name = c("Mick", "John", "Paul"), band = c("Stones", "Beatles", "Beatles")) |> + dplyr::group_by(band) + +# tbl_df with `tribble = TRUE` falls back on tibble() if unsupported cols are found + + Code + construct(tibble::tibble(a = 1:2, b = list(3, 4)), opts_tbl_df(constructor = "tribble")) + Output + tibble::tibble(a = 1:2, b = list(3, 4)) + Code + construct(tibble::tibble(a = 1:2, b = tibble::tibble(x = 3:4)), opts_tbl_df( + constructor = "tribble")) + Output + tibble::tibble( + a = 1:2, + b = tibble::tribble( + ~x, + 3L, + 4L, + ), + ) + +# recycle in tibbles + + Code + construct(tibble::tibble(a = 1:2, b = c(1, 1))) + Output + tibble::tibble(a = 1:2, b = 1) + Code + construct(tibble::tibble(a = c(1, 1), b = c(1, 1))) + Output + tibble::tibble(a = 1, b = 1, .rows = 2L) + Code + construct(tibble::tibble(a = 1:2, b = factor(c("a", "a")))) + Output + tibble::tibble(a = 1:2, b = factor("a")) + Code + construct(tibble::tibble(a = 1:2, b = as.Date(c("2000-01-01", "2000-01-01")))) + Output + tibble::tibble(a = 1:2, b = as.Date("2000-01-01")) + +# duplicate names in tibbles + + Code + construct(tibble::tibble(a = 1, a = 2, .name_repair = "minimal")) + Output + tibble::tibble(a = 1, a = 2, .name_repair = "minimal") + +# non standard names in tibbles + + Code + construct(structure(tibble::tibble(1), names = NULL)) + Output + list(1) |> + structure(row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame")) + Code + construct(structure(tibble::tibble(1), names = "")) + Output + tibble::tibble(1) |> + structure(names = "") + Code + construct(structure(tibble::tibble(1), names = NA)) + Output + tibble::tibble(1) |> + structure(names = NA_character_) + Code + construct(structure(tibble::tibble(1), names = ".rows")) + Output + tibble::tibble(1) |> + structure(names = ".rows") + Code + construct(structure(tibble::tibble(1), names = ".name_repair")) + Output + tibble::tibble(1) |> + structure(names = ".name_repair") + Code + construct(structure(tibble::tibble(1, 2), names = c("a", ""))) + Output + tibble::tibble(a = 1, 2) |> + structure(names = c("a", "")) + Code + construct(structure(tibble::tibble(1, 2), names = c("a", NA))) + Output + tibble::tibble(a = 1, 2) |> + structure(names = c("a", NA)) + Code + construct(structure(tibble::tibble(1, 2), names = c("a", ".rows"))) + Output + tibble::tibble(a = 1, 2) |> + structure(names = c("a", ".rows")) + Code + construct(structure(tibble::tibble(1, 2), names = c("a", ".name_repair"))) + Output + tibble::tibble(a = 1, 2) |> + structure(names = c("a", ".name_repair")) +