[Rd] attach() outputs messages to stdout - should it be stderr?

Henrik Bengtsson hb at biostat.ucsf.edu
Mon Apr 7 17:20:27 CEST 2014


On Mon, Apr 7, 2014 at 1:40 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
>>>>>> Henrik Bengtsson <hb at biostat.ucsf.edu>
>>>>>>     on Sun, 6 Apr 2014 21:33:15 -0700 writes:
>
>     > Contrary to other functions in 'base', attach() output
>     > messages to stdout instead of stdout, e.g.
>
>     >> a <- 1 capture.output(attach(list(a=1)))
>     > [1] "The following object is masked _by_ .GlobalEnv:"
>     > [2] ""
>     > [3] " a"
>
>     > Shouldn't this message go to stderr?
>
> well, it this is changed... it should be changed to use
> message() really -- as library() does.
>
> Then, it will not only go to stderr, but also be something you can
> e.g. use  suppressMessages( . )  with.
>
> I tend to agree to change this from cat() to  message(),
> and will do so after a bit of waiting..

Thanks - sounds good.

I proposed cat(..., file=stderr()) rather that message(), because I
saw it was used in several other place in 'base' - left overs from a
earlier era?

/Henrik

>
> Martin
>
>     > Here's a patch for the local function checkConflicts() of
>     > base::attach(), cf. ditto for base::library() that outputs
>     > to stderr:
>
>> Index: library/base/R/attach.R
>> ===================================================================
>> --- library/base/R/attach.R   (revision 65344)
>> +++ library/base/R/attach.R   (working copy)
>> @@ -73,7 +73,7 @@
>>                                              "The following objects
>> are masked %s %s:\n\n%s\n"),
>>                                     if (i < db.pos) "_by_" else "from",
>>                                     pkg, paste(objs, collapse="\n"))
>> -                    cat(msg)
>> +                    cat(msg, file = stderr())
>>                  }
>>              }
>>          }
>
>> /Henrik



More information about the R-devel mailing list