Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post about ellipsis #152

Open
Bisaloo opened this issue Mar 21, 2022 · 3 comments
Open

Post about ellipsis #152

Bisaloo opened this issue Mar 21, 2022 · 3 comments

Comments

@Bisaloo
Copy link
Member

Bisaloo commented Mar 21, 2022

  • present base R features to play with ...: ...names(), ...elt(n), ...length(), etc.
  • when to use ...?
    • pass arguments to a function chosen by the user (e.g. apply())
    • S3 methods
    • forward compatibility
  • base R function chkDots()
  • explain how to pass a default value to an argument in ...
f <- function(x, ...) {
  
  xargs <- list(...)
  
  if (is.null(xargs$na.rm))
    xargs$na.rm <- TRUE
  
  xargs$x <- x
  
  do.call(quantile, xargs)
  
}

f(1:10)
#>    0%   25%   50%   75%  100% 
#>  1.00  3.25  5.50  7.75 10.00

f(c(1:10, NA))
#>    0%   25%   50%   75%  100% 
#>  1.00  3.25  5.50  7.75 10.00

f(c(1:10, NA), na.rm = FALSE)
#> Error in quantile.default(na.rm = FALSE, x = c(1L, 2L, 3L, 4L, 5L, 6L, : missing values and NaN's not allowed if 'na.rm' is FALSE

Created on 2022-03-11 by the reprex package (v2.0.1.9000)

Bonus: Options for clickbait title

"Everything you've always wanted to know about ..."

@maelle
Copy link
Member

maelle commented Mar 22, 2022

I like the idea and the title 😂

Another use case is to have some sort of DSL. E.g. in glitter we use .... We then handle the passed things with rlang::enquos().

@maelle
Copy link
Member

maelle commented Feb 19, 2024

@maelle
Copy link
Member

maelle commented Feb 19, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants