From daattali at gmail.com  Thu Aug  6 04:35:44 2015
From: daattali at gmail.com (Dean Attali)
Date: Wed, 5 Aug 2015 19:35:44 -0700
Subject: [Rd] 'vapply' not returning list element names when returned
 element is a length-1 list
In-Reply-To: <1A8C1289955EF649A09086A153E2672403B43703C1@GBTEDVPEXCMB04.corp.lgc-group.com>
References: <CA+j8Z+=QN4hOyabjaAtd7gBRSY9RGkXXwRY6uKS_2DoXTp_e_w@mail.gmail.com>
	<1A8C1289955EF649A09086A153E2672403B43703C1@GBTEDVPEXCMB04.corp.lgc-group.com>
Message-ID: <CA+j8Z+mposrAaF6hjt4HPgWq6e6MUwyc-GKmrXz81PEjZdDxYQ@mail.gmail.com>

Thank you, I do see that now. I still don't completely agree with the
behaviour, I hoped there would be a way to not simplify, but thank you for
pointing me to the fact that it is documented.

---
http://deanattali.com

On 5 August 2015 at 05:08, S Ellison <S.Ellison at lgcgroup.com> wrote:

>
>
> > -----Original Message-----
> > From: R-devel [mailto:r-devel-bounces at r-project.org] On Behalf Of Dean
> Attali
> > If i have a function that returns a named list with 2 (or more) elements,
> > then using 'vapply' retains the names of the elements:
> > ....
> > But if the function only returns one element, then the name "foo" is lost
>
> vapply _always simplifies_ according to the documentation.
>
> In the first case (function return value contains more than one element,
> and each ), vapply simplifies to a matrix of two lists (!).  The names
> "foo" and "hello" have been added to the dimnames so you can tell which is
> which.
>
> in the second case the function return value is a single list and not a
> matrix of lists (a simple list is simpler than a matrix of lists). The name
> of the list ('foo') has nowhere to go; instead, you would be assigning the
> list to a named variable and you don't need the name 'foo'.
>
> Whether that is inconsistent is something of a matter of perspective.
> Simplification applied as far as possible will always depend on what
> simplification is possible for the particular return values, so different
> return values provide different behaviour.
>
> S Ellison
>
>
> *******************************************************************
> This email and any attachments are confidential. Any u...{{dropped:12}}



[Rd] 'vapply' not returning list element names when returned element is a length-1 list
Dean Attali