Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions R/translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ rel_find_packages <- function(name) {
"minute" = "lubridate",
"second" = "lubridate",
"wday" = "lubridate",
"day" = "lubridate",
"month" = "lubridate",
"year" = "lubridate",
"ymd" = "lubridate",
"ydm" = "lubridate",
"mdy" = "lubridate",
"myd" = "lubridate",
"dmy" = "lubridate",
"dym" = "lubridate",
"quarter" = "lubridate",
"date" = "lubridate",
"strftime" = "base",
"substr" = "base",

Expand Down
61 changes: 61 additions & 0 deletions tests/testthat/test-as_duckplyr_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,67 @@ test_that("as_duckplyr_df_impl() and mutate(d = if_else(a > 1, \"ok\", NA))", {
expect_identical(pre, post)
})

test_that("as_duckplyr_df_impl() and mutate(d = lubridate::day(d))", {
# Data
test_df <- data.frame(d = as.Date("2025-03-26"))

# Run
pre <- test_df %>% as_duckplyr_df_impl() %>% mutate(d = lubridate::day(d))
post <- test_df %>% mutate(d = lubridate::day(d)) %>% as_duckplyr_df_impl()

# Compare
expect_identical(pre, post)
})

test_that("as_duckplyr_df_impl() and mutate(d = lubridate::month(d))", {
# Data
test_df <- data.frame(d = as.Date("2025-03-26"))

# Run
pre <- test_df %>% as_duckplyr_df_impl() %>% mutate(d = lubridate::month(d))
post <- test_df %>% mutate(d = lubridate::month(d)) %>% as_duckplyr_df_impl()

# Compare
expect_identical(pre, post)
})


test_that("as_duckplyr_df_impl() and mutate(d = lubridate::year(d))", {
# Data
test_df <- data.frame(d = as.Date("2025-03-26"))

# Run
pre <- test_df %>% as_duckplyr_df_impl() %>% mutate(d = lubridate::year(d))
post <- test_df %>% mutate(d = lubridate::year(d)) %>% as_duckplyr_df_impl()

# Compare
expect_identical(pre, post)
})

test_that("as_duckplyr_df_impl() and mutate(d = lubridate::quarter(d))", {
# Data
test_df <- data.frame(d = as.Date("2025-03-26"))

# Run
pre <- test_df %>% as_duckplyr_df_impl() %>% mutate(d = lubridate::quarter(d))
post <- test_df %>% mutate(d = lubridate::quarter(d)) %>% as_duckplyr_df_impl()

# Compare
expect_identical(pre, post)
})

test_that("as_duckplyr_df_impl() and mutate(d = lubridate::ymd(d))", {
# Data
test_df <- data.frame(d = "2025-03-26")

# Run
pre <- test_df %>% as_duckplyr_df_impl() %>% mutate(d = lubridate::ymd(d))
post <- test_df %>% mutate(d = lubridate::ymd(d)) %>% as_duckplyr_df_impl()

# Compare
expect_identical(pre, post)
})

test_that("as_duckplyr_df_impl() and n_groups()", {
withr::local_envvar(DUCKPLYR_FORCE = "FALSE")

Expand Down
13 changes: 13 additions & 0 deletions tools/00-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,19 @@ test_extra_arg_map <- list(
# NA in use
'd = if_else(a > 1, "ok", NA)',

# lubridate
"d = day(a)",
"d = month(a)",
"d = year(a)",
"d = ymd(a)",
"d = ydm(a)",
"d = mdy(a)",
"d = myd(a)",
"d = dmy(a)",
"d = dym(a)",
"d = quarter(a)",
"d = date(a)",

NULL
),
nest_join = "join_by(a)",
Expand Down
11 changes: 6 additions & 5 deletions vignettes/limits.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,19 @@ duckplyr::duckdb_tibble(a = "abbc", .prudence = "stingy") |>

### Date manipulation

Implemented: `lubridate::hour()`, `lubridate::minute()`, `lubridate::second()`, `lubridate::wday()`.
Implemented: `lubridate::hour()`, `lubridate::minute()`, `lubridate::second()`, `lubridate::wday()`, `lubridate::month()`.

```{r}
duckplyr::duckdb_tibble(
a = as.POSIXct("2025-01-11 19:23:46", tz = "UTC"),
.prudence = "stingy"
) |>
mutate(
hour = lubridate::hour(a),
minute = lubridate::minute(a),
second = lubridate::second(a),
wday = lubridate::wday(a)
hour = lubridate::hour(a),
minute = lubridate::minute(a),
second = lubridate::second(a),
wday = lubridate::wday(a),
month = lubridate::month(a)
)
```

Expand Down
Loading