Skip to content

first(named_vector) removes names #2487

Description

@franknarf1
library(data.table)
x = setNames(, "A")
x[1]
#>   A 
#> "A"
first(x)
#> [1] "A"

In example(first), it suggests first(x) and x[1] should be interchangeable, but it doesn't hold here.

Activity

  1. MichaelChirico commented on Nov 16, 2017

    @MichaelChirico
    Member

    To be clear, you aren't requesting that first(x) keeps the names, just that the documentation should clarify this distinction, right?

  2. franknarf1 commented on Nov 16, 2017

    @franknarf1
    ContributorAuthor

    @MichaelChirico Yeah, a very minor request, but it bit me when I was using lapply and then accessing the results by name. Maybe first/last also strips other attributes; I didn't check and don't know the internals, so I'm not sure exactly what the doc should say about it.

  3. Henrik-P commented on Nov 17, 2017

    @Henrik-P
  4. changed the title [-][Doc request] first(named_vector) removes names[/-] [+]first(named_vector) removes names[/+] on Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions