Skip to content

if_else() with named arguments throws errors #730

@gmgui

Description

@gmgui

When using if_else() with named arguments, there's a fall back to dplyr, but when using the function directly without named arguments it works well with duckplyr.

I wasn't expecting the fall back in to dplry this case. I didn't test for other functions.
Is this the expected behavior?

Example

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(duckplyr)
#> Warning: package 'duckplyr' was built under R version 4.5.1
#> The duckplyr package is configured to fall back to dplyr when it encounters an
#> incompatibility. Fallback events can be collected and uploaded for analysis to
#> guide future development. By default, data will be collected but no data will
#> be uploaded.
#> ℹ Automatic fallback uploading is not controlled and therefore disabled, see
#>   `?duckplyr::fallback()`.
#> ✔ Number of reports ready for upload: 11.
#> → Review with `duckplyr::fallback_review()`, upload with
#>   `duckplyr::fallback_upload()`.
#> ℹ Configure automatic uploading with `duckplyr::fallback_config()`.
#> ✔ Overwriting dplyr methods with duckplyr methods.
#> ℹ Turn off with `duckplyr::methods_restore()`.

x <- duckdb_tibble(x = 1:5, y = 1:5, .prudence = "stingy")

# This works:
mutate(x, z = if_else(x >= 2, TRUE, FALSE))
#> # A duckplyr data frame: 3 variables
#>       x     y z    
#>   <int> <int> <lgl>
#> 1     1     1 FALSE
#> 2     2     2 TRUE 
#> 3     3     3 TRUE 
#> 4     4     4 TRUE 
#> 5     5     5 TRUE

# This does not work:
mutate(x, z = if_else(x >= 2, true = TRUE, false = FALSE))
#> Error in `mutate()`:
#> ! This operation cannot be carried out by DuckDB, and the input is a
#>   stingy duckplyr frame.
#> ℹ Use `compute(prudence = "lavish")` to materialize to temporary storage and
#>   continue with duckplyr.
#> ℹ See `vignette("prudence")` for other options.
#> Caused by error in `mutate()`:
#> ! Can't translate named argument `if_else(true = )`.

Created on 2025-07-11 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> Warning in system2("quarto", "-V", stdout = TRUE, env = paste0("TMPDIR=", :
#> running command '"quarto"
#> TMPDIR=C:/Users/gmendozagui/AppData/Local/Temp/Rtmpqmu5Jn/file365010d26c11 -V'
#> had status 1
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.0 (2025-04-11 ucrt)
#>  os       Windows 11 x64 (build 26100)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.utf8
#>  ctype    English_United States.utf8
#>  tz       Europe/Paris
#>  date     2025-07-11
#>  pandoc   3.5 @ C:/Users/GMENDO~1/AppData/Local/Pandoc/ (via rmarkdown)
#>  quarto   NA @ C:\\Users\\GMENDO~1\\AppData\\Local\\Programs\\Quarto\\bin\\quarto.exe
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cachem        1.1.0   2024-05-16 [1] CRAN (R 4.5.0)
#>  cli           3.6.5   2025-04-23 [1] CRAN (R 4.5.0)
#>  collections   0.3.8   2025-05-08 [1] CRAN (R 4.5.0)
#>  DBI           1.2.3   2024-06-02 [1] CRAN (R 4.5.0)
#>  digest        0.6.37  2024-08-19 [1] CRAN (R 4.5.0)
#>  dplyr       * 1.1.4   2023-11-17 [1] CRAN (R 4.5.0)
#>  duckdb        1.3.2   2025-07-09 [1] CRAN (R 4.5.0)
#>  duckplyr    * 1.1.0   2025-05-08 [1] CRAN (R 4.5.1)
#>  evaluate      1.0.4   2025-06-18 [1] CRAN (R 4.5.0)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.5.0)
#>  fs            1.6.6   2025-04-12 [1] CRAN (R 4.5.0)
#>  generics      0.1.4   2025-05-09 [1] CRAN (R 4.5.0)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.1)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.5.0)
#>  jsonlite      2.0.0   2025-03-27 [1] CRAN (R 4.5.0)
#>  knitr         1.50    2025-03-16 [1] CRAN (R 4.5.0)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.5.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.2)
#>  memoise       2.0.1   2021-11-26 [1] CRAN (R 4.5.0)
#>  pillar        1.11.0  2025-07-04 [1] CRAN (R 4.5.1)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.5.0)
#>  R6            2.6.1   2025-02-15 [1] CRAN (R 4.5.0)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.5.0)
#>  rlang         1.1.6   2025-04-11 [1] CRAN (R 4.5.0)
#>  rmarkdown     2.29    2024-11-04 [1] CRAN (R 4.5.0)
#>  rstudioapi    0.17.1  2024-10-22 [1] CRAN (R 4.5.0)
#>  sessioninfo   1.2.3   2025-02-05 [1] CRAN (R 4.5.0)
#>  tibble        3.3.0   2025-06-08 [1] CRAN (R 4.5.0)
#>  tidyselect    1.2.1   2024-03-11 [1] CRAN (R 4.5.0)
#>  vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.3.2)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.5.0)
#>  xfun          0.52    2025-04-02 [1] CRAN (R 4.5.0)
#>  yaml          2.3.10  2024-07-26 [1] CRAN (R 4.5.0)
#> 
#>  [1] C:/Data/Rpackages
#>  [2] C:/Program Files/R/R-4.5.0/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Metadata

Metadata

Assignees

Labels

featurea feature request or enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions