Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

  • Understand the issue: if_else() with named arguments throws errors
  • Initial fix for if_else with named arguments
  • Address maintainer feedback to apply call_match() to all function calls
  • Simplify: Remove rel_get_call_match_def() function, use dynamic function lookup from package namespace
  • Add rel_primitives vector to identify operators and functions that don't need call_match()
  • Apply call_match() generically using get0(name, envir = asNamespace(pkg)) for non-primitive functions
  • Verify all tests pass
  • Run code review and security checks
Original prompt

This section details on the original issue you should resolve

<issue_title>if_else() with named arguments throws errors</issue_title>
<issue_description>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-...

</details>

- Fixes tidyverse/duckplyr#730

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI changed the title [WIP] Fix if_else() behavior with named arguments Support if_else() with named arguments Nov 26, 2025
Copilot AI requested a review from krlmlr November 26, 2025 11:00
Copilot finished work on behalf of krlmlr November 26, 2025 11:00
@krlmlr
Copy link
Member

krlmlr commented Nov 26, 2025

@copilot: All function calls should be treated with rlang::arg_match() .

Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot: All function calls should be treated with rlang::arg_match() .

Implemented in aa90b65. Added rel_get_call_match_def() function that returns the function definition for call_match() for each supported function. call_match() is now applied generically early in rel_translate_lang() for all supported functions:

  • dplyr: if_else, coalesce, lag, lead, row_number, n
  • base: abs, log, log10, is.na, as.integer, sub, gsub, grepl, strftime, substr, suppressWarnings
  • lubridate: wday, hour, minute, second

Aggregation functions (sum, min, max, any, all, mean, sd, median, n_distinct) are still handled specially with custom definitions to support the na.rm argument with ... signatures.

Copilot finished work on behalf of krlmlr November 26, 2025 16:23
Copy link
Member

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • rel_get_call_match_def() is not needed, we know the package and can look up the function definitions directly.
  • Move the logic of handling primitives early. Rely only on named argument lookup after matching.

Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

  • rel_get_call_match_def() is not needed, we know the package and can look up the function definitions directly.
  • Move the logic of handling primitives early. Rely only on named argument lookup af...

Addressed in f3d1dce. Removed rel_get_call_match_def() and now dynamically look up function definitions using get0(name, envir = asNamespace(pkg)). Added rel_primitives vector to identify operators and aggregation functions that should be handled specially (operators skip call_match(), aggregations use custom definitions for na.rm support).

Copilot AI requested a review from krlmlr November 26, 2025 16:51
Copilot finished work on behalf of krlmlr November 26, 2025 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants