[Rd] Proposing a change in the base::sink interface for type argument
macqueen1 at llnl.gov
Wed Mar 18 22:42:27 CET 2015
It's only an illusion until one actually tries providing a vector.
> sink('foo', type=c('s','m'))
Error in match.arg(type) : 'arg' must be of length 1
The additional benefit of match.arg() which you may have not appreciated
is that it allows the user to abbreviate. That is,
> sink('foo', type='o')
is valid usage. The essential concept of match.arg() is that it tries to
match whatever the user supplied with one, and only one, of the values
provided in the argument's default value, and that is the value used in
the rest of the function.
> foo <- function(arg=c('aa','bb','cc')) cat(match.arg(arg),'\n')
Error in match.arg(arg) : 'arg' should be one of "aa", "bb", "cc"
Being "non-intuitive" or puzzling to people coming from other languages is
not a sufficient reason for a change. Obviously, different languages have
different features, otherwise, why bother to have different languages?
And yes, match.arg() is widely used in R. I find it quite useful in my own
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
On 3/16/15, 10:08 PM, "Hamid Bazzaz" <hhamid at gmail.com> wrote:
>Here is the current interface:
>sink(file=NULL, append=FALSE, type = c("output", "message"), split=FALSE)
>However, reading the implementation there is implicit assumption that type
>is a single character value:
>I'm finding this very confusing as the interface is giving a default value
>of a character _vector_ causing the illusion that by default both
>output/message will be redirected.
>I'm proposing either a change in the interface so it is a single character
>(either output or message) or a loop in the implementation on all values
>type so it will actually be considered a vector. Here is an example change
>for the former:
>Just wondering what people think and if this makes sense.
>Thanks a lot,
> [[alternative HTML version deleted]]
>R-devel at r-project.org mailing list
More information about the R-devel