Skip to content

Improve performance of enframe #353

Closed

Description

@hadley

By using lower level constructor.

library(tibble)
options(digits = 3)

enframe2 <- function(x, name = "name", value = "value") {
  if (rlang::is_null(names(x))) {
    l <- list(seq_along(x), x)
  } else {
    l <- list(names(x), unname(x))
  }
  names(l) <- c(name, value)
  new_tibble(l)
}

x <- setNames(letters, letters)

microbenchmark::microbenchmark(
  enframe(x),
  enframe2(x)
)
#> Unit: microseconds
#>         expr    min     lq mean median     uq   max neval cld
#>   enframe(x) 1066.2 1116.9 1792 1185.7 1270.3 39110   100   b
#>  enframe2(x)   77.9   85.2  157   89.9   97.2  4283   100  a

(This is with dev rlang so I'm a little surprised that the speed difference is still so huge - it's probably worth a little profiling of data_frame)

Activity

  1. krlmlr commented on Jan 4, 2018

    @krlmlr
    Member

    Will add this to #348.

  2. added a commit that references this issue on Jan 15, 2018
    bd6af96
  3. added 3 commits that reference this issue on Jan 15, 2018
  4. github-actions commented on Dec 11, 2020

    @github-actions
    Contributor

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

  5. locked and limited conversation to collaborators on Dec 11, 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

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions