* _join with an empty suffix

Fair warning: this may hang your operating system.

*_join() from dplyr fails if one of the left or right suffixes is specified as empty ( '' ), for example.

 inner_join(data.frame(x=1, y=2), data.frame(x=1, y=3), by='x', suffix=c('', '.b')) 

While the following works just fine:

 inner_join(data.frame(x=1, y=2), data.frame(x=1, y=3), by='x', suffix=c('.a', '.b')) 

Meanwhile, S3 generic merge() (base) has no problems with empty suffixes:

 merge(data.frame(x=1, y=2), data.frame(x=1, y=3), by='x', suffixes=c('', '.b')) 

Information about the dplyr package:

 > packageVersion('dplyr') [1] '0.5.0' 

Version Information R:

 > version platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 3 minor 3.0 year 2016 month 05 day 03 svn rev 70573 language R version.string R version 3.3.0 (2016-05-03) nickname Supposedly Educational 
+6
source share
1 answer

It was fun when I stumbled upon this mistake. The following will accomplish the desired effect using dplyr using suffixes '' and .b

 library(dplyr) inner_join(data.frame(x=1, y=2), data.frame(x=1, y=3), by='x', suffix=c('.a', '.b')) %>% setNames(gsub('\\.a$', '', names(.))) 
+4
source

Source: https://habr.com/ru/post/1012293/


All Articles