Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename must not allow duplicated column names #4643

Closed
holgerbrandl opened this issue Dec 6, 2019 · 1 comment
Closed

rename must not allow duplicated column names #4643

holgerbrandl opened this issue Dec 6, 2019 · 1 comment
Labels
bug selection 🧺

Comments

@holgerbrandl
Copy link

holgerbrandl commented Dec 6, 2019

Expected behaviour: rename should not allow duplicated columns names.

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
@hadley
Copy link
Member

hadley commented Dec 10, 2019

Simpler reprex:

library(dplyr, warn.conflicts = FALSE)
iris %>% rename(Species = Sepal.Length) %>% names()
#> [1] "Species"      "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"

Created on 2019-12-10 by the reprex package (v0.3.0)

@hadley hadley added bug selection 🧺 labels Dec 10, 2019
hadley added a commit that referenced this issue Jan 8, 2020
@hadley hadley closed this as completed in 3d45972 Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug selection 🧺
Projects
None yet
Development

No branches or pull requests

2 participants