Can't transform a data frame with duplicate names

I have started getting these strange errors with simple commands. For example,
I am attempting to sort and filter a data frame by a single key value:

apidata$geoid <- paste0(apidata$state,apidata$county)
        
        tmp_data <- apidata %>%  arrange(geoid)

which produces this error:

Error in `arrange()`:
! Problem with the implicit `transmute()` step.
Caused by error in `transmute()`:
! Can't transform a data frame with duplicate names.
Run `rlang::last_error()` to see where the error occurred.
Called from: signal_abort(cnd, .file)

This is pretty basic dplyr code. I have checked the variables, "geoid" is not duplicated in the columns of my data frame, nor are there any duplicate records in the data frame.

here is the session info:

R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

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

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

other attached packages:
 [1] jsonlite_1.8.0    openxlsx_4.2.5    readxl_1.3.1      censusapi_0.7.1   tidycensus_1.1.2  forcats_0.5.1     stringr_1.4.0    
 [8] dplyr_1.0.8       purrr_0.3.4       readr_2.1.2       tidyr_1.2.0       tibble_3.1.6      ggplot2_3.3.5     tidyverse_1.3.1  
[15] RPostgreSQL_0.7-3 DBI_1.1.2        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8         lubridate_1.8.0    lattice_0.20-45    class_7.3-19       assertthat_0.2.1   utf8_1.2.2         R6_2.5.1          
 [8] cellranger_1.1.0   backports_1.4.1    reprex_2.0.1       e1071_1.7-9        httr_1.4.2         pillar_1.7.0       rlang_1.0.1       
[15] uuid_1.0-3         rstudioapi_0.13    rgdal_1.5-28       foreign_0.8-81     munsell_0.5.0      proxy_0.4-26       broom_0.7.12      
[22] compiler_4.1.2     modelr_0.1.8       pkgconfig_2.0.3    tigris_1.6         tidyselect_1.1.2   fansi_1.0.2        crayon_1.5.0      
[29] tzdb_0.2.0         dbplyr_2.1.1       withr_2.5.0        later_1.3.0        sf_1.0-7           rappdirs_0.3.3     grid_4.1.2        
[36] gtable_0.3.0       lifecycle_1.0.1    magrittr_2.0.2     units_0.8-0        scales_1.1.1       zip_2.2.0          KernSmooth_2.23-20
[43] cli_3.2.0          stringi_1.7.6      fs_1.5.2           sp_1.4-6           xml2_1.3.3         ellipsis_0.3.2     generics_0.1.2    
[50] vctrs_0.3.8        tools_4.1.2        glue_1.6.2         hms_1.1.1          colorspace_2.0-3   maptools_1.1-3     pool_0.1.6        
[57] classInt_0.4-3     rvest_1.0.2        haven_2.4.3       

What is happening?
TIA

This must not be my day...
I am getting the same error with a mutate command:

tmp_data <- apidata %>%
           mutate(geoid = paste0(state,county)) %>%
          filter(geoid %in% ctyFips)

returns

Error in `mutate()`:
! Can't transform a data frame with duplicate names.
Run `rlang::last_error()` to see where the error occurred.

is this a dplyr problem?
AB

Hi,

In order for us to help you with your question, please provide us a minimal reproducible example where you provide a minimal (dummy) dataset and code that can recreate the issue. Once we have that, we can go from there. For help on creating a Reprex, see this guide:

Good luck!
PJ

You should run

names(apidata)

To see what your column names are.

1 Like

Have you performed some of the basic debugging as suggested in the responses?
1- execute the 'rlang::last_error()' and see if you get more details
2- try distinct(apidata$state) %>% view () # to inspect the values in the state, do same for country, anything odd in there?
3- execute paste0(state,county) and see if that works, inspect the values generated

good luck

Thanks for the suggestions. There was a problem with rlang, which is a support library for the tidyverse suite. I removed rlang and reinstalled it. Things have been working okay.
So it goes.
Cheers--
AB

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.