Skip to content

Mutate Drops Row Names #5418

Description

@jam1015

Hey! I know that row names on tibbles are deprecated (which I disagree with but that is beside the point) but I think that for now, given that someone wants to continue using this deprecated feature, functions like mutate should not drop rownames in cases by default where the user wants to keep them. There are constructs outside of the tidyverse that still use rownames; for example the bioconductor object 'eset' uses them in important ways and there are tools that take esets and not more modern bioconductor objects. So if I want to use tibbles and dplyr verbs when constructing esets I have to do inconvenient workarounds, or not use dplyr. So what I want is for tidyverse functions to preserve rownames wherever possible, even though I know it is not possible with certain things (like joins where rows are added).

Here is a simple example:

library(tidyverse)
small_tibble <- mpg[1:3,1:3]
rownames(small_tibble) <- c("snap","cracke","pop")
print(rownames(small_tibble)) #setting rownames was successful
small_tibble_mutated <- small_tibble %>% mutate(displ = displ^2)
print(rownames(small_tibble_mutated)) #rownames disappeared

Activity

  1. idavydov commented on Aug 6, 2020

    @idavydov

    I'm also experiencing this in dplyr 1.0.1. Seems like a bug to me.

    x <- data.frame(p=1:2, row.names=c('a','b'))
    x
    #>   p
    #> a 1
    #> b 2
    dplyr::mutate(x, q=2)
    #>   p q
    #> 1 1 2
    #> 2 2 2

    Created on 2020-08-06 by the reprex package (v0.3.0)

    Session info
    devtools::session_info()
    #> ─ Session info ───────────────────────────────────────────────────────────────
    #>  setting  value                       
    #>  version  R version 3.6.1 (2019-07-05)
    #>  os       CentOS Linux 7 (Core)       
    #>  system   x86_64, linux-gnu           
    #>  ui       X11                         
    #>  language (EN)                        
    #>  collate  en_US.UTF-8                 
    #>  ctype    en_US.UTF-8                 
    #>  tz       Europe/Zurich               
    #>  date     2020-08-06                  
    #> 
    #> ─ Packages ───────────────────────────────────────────────────────────────────
    #>  package     * version    date       lib source                            
    #>  assertthat    0.2.1.9000 2020-07-07 [2] Github (hadley/assertthat@50dc4b0)
    #>  backports     1.1.8      2020-06-17 [2] CRAN (R 3.6.1)                    
    #>  callr         3.4.3      2020-03-28 [2] CRAN (R 3.6.1)                    
    #>  cli           2.0.2      2020-02-28 [2] CRAN (R 3.6.1)                    
    #>  crayon        1.3.4      2017-09-16 [2] CRAN (R 3.6.1)                    
    #>  desc          1.2.0      2018-05-01 [2] CRAN (R 3.6.1)                    
    #>  devtools      2.3.1      2020-07-21 [2] CRAN (R 3.6.1)                    
    #>  digest        0.6.25     2020-02-23 [2] CRAN (R 3.6.1)                    
    #>  dplyr         1.0.1      2020-07-31 [2] CRAN (R 3.6.1)                    
    #>  ellipsis      0.3.1      2020-05-15 [2] CRAN (R 3.6.1)                    
    #>  evaluate      0.14       2019-05-28 [2] CRAN (R 3.6.1)                    
    #>  fansi         0.4.1      2020-01-08 [2] CRAN (R 3.6.1)                    
    #>  fs            1.5.0      2020-07-31 [2] CRAN (R 3.6.1)                    
    #>  generics      0.0.2      2018-11-29 [2] CRAN (R 3.6.1)                    
    #>  glue          1.4.1      2020-05-13 [2] CRAN (R 3.6.1)                    
    #>  highr         0.8        2019-03-20 [2] CRAN (R 3.6.1)                    
    #>  htmltools     0.5.0      2020-06-16 [2] CRAN (R 3.6.1)                    
    #>  knitr         1.29       2020-06-23 [2] CRAN (R 3.6.1)                    
    #>  lifecycle     0.2.0      2020-03-06 [2] CRAN (R 3.6.1)                    
    #>  magrittr      1.5        2014-11-22 [2] CRAN (R 3.6.1)                    
    #>  memoise       1.1.0      2017-04-21 [2] CRAN (R 3.6.1)                    
    #>  pillar        1.4.6      2020-07-10 [2] CRAN (R 3.6.1)                    
    #>  pkgbuild      1.1.0      2020-07-13 [2] CRAN (R 3.6.1)                    
    #>  pkgconfig     2.0.3      2019-09-22 [2] CRAN (R 3.6.1)                    
    #>  pkgload       1.1.0      2020-05-29 [2] CRAN (R 3.6.1)                    
    #>  prettyunits   1.1.1      2020-01-24 [2] CRAN (R 3.6.1)                    
    #>  processx      3.4.3      2020-07-05 [2] CRAN (R 3.6.1)                    
    #>  ps            1.3.3      2020-05-08 [2] CRAN (R 3.6.1)                    
    #>  purrr         0.3.4      2020-04-17 [2] CRAN (R 3.6.1)                    
    #>  R6            2.4.1      2019-11-12 [2] CRAN (R 3.6.1)                    
    #>  remotes       2.2.0      2020-07-21 [2] CRAN (R 3.6.1)                    
    #>  rlang         0.4.7      2020-07-09 [2] CRAN (R 3.6.1)                    
    #>  rmarkdown     2.3        2020-06-18 [2] CRAN (R 3.6.1)                    
    #>  rprojroot     1.3-2      2018-01-03 [2] CRAN (R 3.6.1)                    
    #>  sessioninfo   1.1.1      2018-11-05 [2] CRAN (R 3.6.1)                    
    #>  stringi       1.4.6      2020-02-17 [2] CRAN (R 3.6.1)                    
    #>  stringr       1.4.0      2019-02-10 [2] CRAN (R 3.6.1)                    
    #>  testthat      2.3.2      2020-03-02 [2] CRAN (R 3.6.1)                    
    #>  tibble        3.0.3      2020-07-10 [2] CRAN (R 3.6.1)                    
    #>  tidyselect    1.1.0      2020-05-11 [2] CRAN (R 3.6.1)                    
    #>  usethis       1.6.1      2020-04-29 [2] CRAN (R 3.6.1)                    
    #>  vctrs         0.3.2      2020-07-15 [2] CRAN (R 3.6.1)                    
    #>  withr         2.2.0      2020-04-20 [2] CRAN (R 3.6.1)                    
    #>  xfun          0.16       2020-07-24 [2] CRAN (R 3.6.1)                    
    #>  yaml          2.2.1      2020-02-01 [2] CRAN (R 3.6.1)                    
    #> 
    #> [1] /...
    #> [2] /...
    #> [3] /...
  2. DavisVaughan commented on Aug 18, 2020

    @DavisVaughan
    Member

    I think dplyr_col_modify.data.frame() needs a line like:

    row_names <- .row_names_info(data, type = 0L)
    out <- new_data_frame(out, n = nrow(data), row.names = row_names)
    
  3. added a commit that references this issue on Aug 28, 2020
    ce95112
  4. added 2 commits that reference this issue on Nov 9, 2020
    c15b848
    2da2954
  5. added a commit that references this issue on Nov 12, 2020
    6307231
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

    bugan unexpected problem or unintended behaviorvctrs ↗️

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions