safe_median() works stats::median() but warns if some elements of ... are never used.

safe_median(x, ...)

# S3 method for numeric
safe_median(x, ..., na.rm = TRUE)

Arguments

x

Numeric vector

...

Additional arguments passed on to methods.

na.rm

For numeric method, should missing values be removed?

Examples

x <- c(1:10, NA) safe_median(x, na.rm = TRUE)
#> [1] 5.5
median(x, na.rm = TRUE)
#> [1] 5.5
try(median(x, na.mr = TRUE))
#> [1] NA
try(safe_median(x, na.mr = TRUE))
#> Error : 1 components of `...` were not used. #> #> We detected these problematic arguments: #> * `na.mr` #> #> Did you misspecify an argument? #> Backtrace: #> █ #> 1. ├─base::tryCatch(...) #> 2. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) #> 3. │ ├─base:::tryCatchOne(...) #> 4. │ │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 5. │ └─base:::tryCatchList(expr, names[-nh], parentenv, handlers[-nh]) #> 6. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 7. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 8. ├─base::withCallingHandlers(...) #> 9. ├─base::saveRDS(...) #> 10. ├─base::do.call(...) #> 11. ├─(function (what, args, quote = FALSE, envir = parent.frame()) ... #> 12. └─(function (..., crayon_enabled, crayon_colors, pkgdown_internet) ... #> 13. └─pkgdown::build_site(...) #> 14. └─pkgdown:::build_site_local(...) #> 15. └─pkgdown::build_reference(...) #> 16. └─purrr::map(...) #> 17. └─pkgdown:::.f(.x[[i]], ...) #> 18. └─pkgdown:::data_reference_topic(...) #> 19. └─pkgdown:::run_examples(...) #> 20. └─pkgdown:::highlight_examples(code, topic, env = env) #> 21. └─evaluate::evaluate(x, child_env(env), new_device = TRUE) #> 22. └─evaluate:::evaluate_call(...) #> 23. ├─evaluate:::timing_fn(...) #> 24. ├─evaluate:::handle(...) #> 25. │ └─base::try(f, silent = TRUE) #> 26. │ └─base::tryCatch(...) #> 27. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) #> 28. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 29. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 30. ├─base::withCallingHandlers(...) #> 31. ├─base::withVisible(eval(expr, envir, enclos)) #> 32. └─base::eval(expr, envir, enclos) #> 33. └─base::eval(expr, envir, enclos) #> 34. ├─base::try(safe_median(x, na.mr = TRUE)) #> 35. │ └─base::tryCatch(...) #> 36. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) #> 37. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 38. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 39. └─ellipsis::safe_median(x, na.mr = TRUE) #> 40. └─(function (env = parent.frame(), action) ... #> 41. └─ellipsis:::action_dots(...)
try(median(1, 2, 3))
#> [1] 1
try(safe_median(1, 2, 3))
#> Error : 2 components of `...` were not used. #> #> We detected these problematic arguments: #> * `..1` #> * `..2` #> #> Did you misspecify an argument? #> Backtrace: #> █ #> 1. ├─base::tryCatch(...) #> 2. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) #> 3. │ ├─base:::tryCatchOne(...) #> 4. │ │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 5. │ └─base:::tryCatchList(expr, names[-nh], parentenv, handlers[-nh]) #> 6. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 7. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 8. ├─base::withCallingHandlers(...) #> 9. ├─base::saveRDS(...) #> 10. ├─base::do.call(...) #> 11. ├─(function (what, args, quote = FALSE, envir = parent.frame()) ... #> 12. └─(function (..., crayon_enabled, crayon_colors, pkgdown_internet) ... #> 13. └─pkgdown::build_site(...) #> 14. └─pkgdown:::build_site_local(...) #> 15. └─pkgdown::build_reference(...) #> 16. └─purrr::map(...) #> 17. └─pkgdown:::.f(.x[[i]], ...) #> 18. └─pkgdown:::data_reference_topic(...) #> 19. └─pkgdown:::run_examples(...) #> 20. └─pkgdown:::highlight_examples(code, topic, env = env) #> 21. └─evaluate::evaluate(x, child_env(env), new_device = TRUE) #> 22. └─evaluate:::evaluate_call(...) #> 23. ├─evaluate:::timing_fn(...) #> 24. ├─evaluate:::handle(...) #> 25. │ └─base::try(f, silent = TRUE) #> 26. │ └─base::tryCatch(...) #> 27. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) #> 28. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 29. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 30. ├─base::withCallingHandlers(...) #> 31. ├─base::withVisible(eval(expr, envir, enclos)) #> 32. └─base::eval(expr, envir, enclos) #> 33. └─base::eval(expr, envir, enclos) #> 34. ├─base::try(safe_median(1, 2, 3)) #> 35. │ └─base::tryCatch(...) #> 36. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) #> 37. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 38. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) #> 39. └─ellipsis::safe_median(1, 2, 3) #> 40. └─(function (env = parent.frame(), action) ... #> 41. └─ellipsis:::action_dots(...)