One of my built-in functions calls grep()with a value = TRUEhard-coded one. I would like to convey all the additional arguments , except value , grep()through .... Below are the two tests below that I have done so far, none of which are doing their job.
What is the best way to exclude one or more additional arguments when using ... ?
Practical Function 1:
f <- function(pattern, x, ...)
{
dots <- list(...)
if('value' %in% names(dots))
dots <- dots[!grepl('value', names(dots))]
grep(pattern, x, value = TRUE, ...)
}
XX <- c('bct', 'abc', 'fds', 'ddabcff', 'jkl')
f('abc', XX, value = TRUE)
f('abc', XX, invert = TRUE)
f('ABC', XX, ignore.case = TRUE)
Practical Function 2:
h <- function(pattern, x, ...) x[grep(pattern, x, ...)]
#
h('abc', XX, value = TRUE)
# [1] NA NA
h('abc', XX, invert = TRUE)
# [1] "bct" "fds" "jkl"
h('ABC', XX, ignore.case = TRUE)
# [1] "abc" "ddabcff"
source
share