Skip to content

rename must not allow duplicated column names #4643

@holgerbrandl

Description

@holgerbrandl

Expected behaviour: rename should not allow duplicated columns names.

Details

Currently it does:

require(dplyr)
sessionInfo()
iris %>% tbl_df %>% rename(Species= Sepal.Length)

The output is

λ R

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> require(dplyr)
Loading required package: dplyr

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] dplyr_0.8.3

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5 compiler_3.6.1   magrittr_1.5     assertthat_0.2.1
 [5] R6_2.4.0         pillar_1.4.2     glue_1.3.1       tibble_2.1.3
 [9] crayon_1.3.4     Rcpp_1.0.2       pkgconfig_2.0.2  rlang_0.4.0
[13] purrr_0.3.2
> iris %>% tbl_df %>% rename(Species= Sepal.Length)
# A tibble: 150 x 5
   Species Sepal.Width Petal.Length Petal.Width Species
     <dbl>       <dbl>        <dbl>       <dbl> <fct>
 1     5.1         3.5          1.4         0.2 setosa
 2     4.9         3            1.4         0.2 setosa
 3     4.7         3.2          1.3         0.2 setosa
 4     4.6         3.1          1.5         0.2 setosa
 5     5           3.6          1.4         0.2 setosa
 6     5.4         3.9          1.7         0.4 setosa
 7     4.6         3.4          1.4         0.3 setosa
 8     5           3.4          1.5         0.2 setosa
 9     4.4         2.9          1.4         0.2 setosa
10     4.9         3.1          1.5         0.1 setosa
# ... with 140 more rows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorselection 🧺tidyselect, scoped verbs, etc.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions