[Rd] Proposing a change in the base::sink interface for type argument
hhamid at gmail.com
Thu Mar 19 04:15:25 CET 2015
Thanks Don/Kasper for the detailed explanation. Understood the idea behind
match.arg. Meanwhile, it might look handy, the part I am finding tricky is
that it makes the signature of the function misleading. That is, client
would have no idea that a particular arg is accessed through match.arg. So,
unless (A) this is well-documented or (B) one go read the implementation,
he wouldn't know the actual type of the arg is atomic not a vector. To be
fair, in the case of sink, documentation is clear that type is a character.
So, I am dropping my request. But, I probably won't use match.arg myself
given the illusion it causes in the interface of a function.
On Wed, Mar 18, 2015 at 4:48 PM, Kasper Daniel Hansen <
kasperdanielhansen at gmail.com> wrote:
> In other words: this is a standard programming paradigm in R/S which
> (unfortunately) is not widely known, based on my network. It is really
> nice for developers.
> On Wed, Mar 18, 2015 at 5:42 PM, MacQueen, Don <macqueen1 at llnl.gov> wrote:
>> 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.
>> For example:
>> > foo <- function(arg=c('aa','bb','cc')) cat(match.arg(arg),'\n')
>> > foo('a')
>> > foo('b')
>> > foo('x')
>> Error in match.arg(arg) : 'arg' should be one of "aa", "bb", "cc"
>> > foo('aa')
>> 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
>> Don MacQueen
>> 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:
>> >Hi folks,
>> >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
>> >is a single character value:
>> >I'm finding this very confusing as the interface is giving a default
>> >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
>> >(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
>> >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
>> R-devel at r-project.org mailing list
[[alternative HTML version deleted]]
More information about the R-devel