Skip to content

Post about ellipsis #152

Open
Open
@Bisaloo

Description

@Bisaloo
  • 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 ..."

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions