From hp@ge@@on@g|thub @end|ng |rom gm@||@com  Wed Dec  1 07:45:15 2021
From: hp@ge@@on@g|thub @end|ng |rom gm@||@com (=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=)
Date: Tue, 30 Nov 2021 22:45:15 -0800
Subject: [Rd] 
 mapply(): Special case of USE.NAMES=TRUE with recent R-devel updates
In-Reply-To: <CAFDcVCRaGk8b3jeHQq5AL1LQkY1H7GjLRGTcrCPQ9UHye1FTgw@mail.gmail.com>
References: <CAFDcVCRaGk8b3jeHQq5AL1LQkY1H7GjLRGTcrCPQ9UHye1FTgw@mail.gmail.com>
Message-ID: <842f72bb-53fa-1755-5480-1e351d9f56cb@gmail.com>

And also:

   > mapply(paste, c(a="A"), character(), USE.NAMES = TRUE)

   Error in names(answer) <- names1 :

     'names' attribute [1] must be the same length as the vector [0]


When the shortest arguments get recycled to the length of the longest, 
shouldn't their names also get recycled?

   > mapply(paste, c(a="A", b="B"), letters[1:6], USE.NAMES=TRUE)

       a     b  <NA>  <NA>  <NA>  <NA>

   "A a" "B b" "A c" "B d" "A e" "B f"

That's assuming that rep() accurately materializes recycling (I hope it 
does):

   > rep(c(a="A", b="B"), length.out=6)

     a   b   a   b   a   b

   "A" "B" "A" "B" "A" "B"


   > rep(c(a="A", b="B"), length.out=0)

   named character(0)


I always wished that the process of recycling which happens everywhere 
all the time in R was implemented in its own dedicated function 
recycle(). But that's another story.

Anyways, back to mapply(): Once what happens to the names during 
recycling is clarified, there should be no need to be explicit about 
what should happen when the length "of the first ... argument" is zero 
because it will no longer be a special case.

Cheers,
H.


On 30/11/2021 22:10, Henrik Bengtsson wrote:
> Hi,
> 
> in R-devel (4.2.0), we now get:
> 
>> mapply(paste, "A", character(), USE.NAMES = TRUE)
> named list()
> 
> Now, in ?mapply we have:
> 
> USE.NAMES: logical; use the names of the first ... argument, or if
> that is an unnamed character vector, use that vector as the names.
> 
> This basically says we should get:
> 
>> answer <- list()
>> first <- "A"
>> names(answer) <- first
> 
> which obviously is an error. The help is not explicit what should
> happen when the length "of the first ... argument" is zero, but the
> above behavior effectively does something like:
> 
>> answer <- list()
>> first <- "A"
>> names(answer) <- first[seq_along(answer)]
>> answer
> named list()
> 
> Is there a need for the docs to be updated, or should the result be an
> unnamed empty list?
> 
> /Henrik
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Herv? Pag?s

Bioconductor Core Team
hpages.on.github at gmail.com



[Rd] mapply(): Special case of USE.NAMES=TRUE with recent R-devel updates
=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=