From henr|k@bengt@@on @end|ng |rom gm@||@com  Wed Dec  1 18:59:13 2021
From: henr|k@bengt@@on @end|ng |rom gm@||@com (Henrik Bengtsson)
Date: Wed, 1 Dec 2021 09:59:13 -0800
Subject: [Rd] R-devel: as.vector(x,
 mode = "list") drops attributes despite documented not to
Message-ID: <CAFDcVCQJ2+X_jOEtyJaYb+YHuN4ohGber5pAJDWzCZXNS435Zw@mail.gmail.com>

Hi,

in R 4.1.2 we have:

> x <- structure(as.list(1:2), dim = c(1,2))
> x
     [,1] [,2]
[1,] 1    2
> as.vector(x, mode = "list")
     [,1] [,2]
[1,] 1    2

whereas in recent versions of R-devel (4.2.0) we have:

> x <- structure(as.list(1:2), dim = c(1,2))
> x
     [,1] [,2]
[1,] 1    2
> as.vector(x, mode = "list")
[[1]]
[1] 1

[[2]]
[1] 2

However, as I read ?as.vector, dropping of attributes should _not_
happen for non-atomic results such as lists.  Is the new behavior a
mistake?

Specifically, ?as.vector says:

'as.vector', a generic, attempts to coerce its argument into a vector
of mode 'mode' (the default is to coerce to whichever vector mode is
most convenient): if the result is atomic all attributes are removed.

[...]

Details:

The atomic modes are "logical", "integer", "numeric" (synonym
"double"), "complex", "character" and "raw".

[...] On the other hand, as.vector removes all attributes including
names for results of atomic mode (but not those of mode "list" nor
"expression").

Value:

[...]

For as.vector, a vector (atomic or of type list or expression). All
attributes are removed from the result if it is of an atomic mode, but
not in general for a list result. The default method handles 24 input
types and 12 values of type: the details of most coercions are
undocumented and subject to change.

/Henrik



[Rd] R-devel: as.vector(x, mode = "list") drops attributes despite documented not to
Henrik Bengtsson