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

unite throws error when trying to unite all columns if column selection is left empty #355

meow9th opened this issue Aug 31, 2017 · 2 comments


Copy link

@meow9th meow9th commented Aug 31, 2017

The documentation for unite implies that unite can be used to unite all columns if column selection is left empty:

A selection of columns. If empty, all variables are selected.

However, when attempting to do so, an error is thrown:

tidyr::unite(mtcars, 'all_cols')

Results in:

Error in if (!after) c(values, x) else if (after >= lengx) c(x, values) else c(x[1L:after],  : 
  missing value where TRUE/FALSE needed

When all columns are specified explicitly, no error is thrown:

tidyr::unite(mtcars, 'all_cols', mpg:carb)

Results in:

Mazda RX4               21_6_160_110_3.9_2.62_16.46_0_1_4_4
Mazda RX4 Wag          21_6_160_110_3.9_2.875_17.02_0_1_4_4
Datsun 710            22.8_4_108_93_3.85_2.32_18.61_1_1_4_1
Hornet 4 Drive      21.4_6_258_110_3.08_3.215_19.44_1_0_3_1
Hornet Sportabout    18.7_8_360_175_3.15_3.44_17.02_0_0_3_2
Valiant              18.1_6_225_105_2.76_3.46_20.22_1_0_3_1
Duster 360           14.3_8_360_245_3.21_3.57_15.84_0_0_3_4
Merc 240D              24.4_4_146.7_62_3.69_3.19_20_1_0_4_2
Merc 230             22.8_4_140.8_95_3.92_3.15_22.9_1_0_4_2
Merc 280            19.2_6_167.6_123_3.92_3.44_18.3_1_0_4_4
Merc 280C           17.8_6_167.6_123_3.92_3.44_18.9_1_0_4_4
Merc 450SE          16.4_8_275.8_180_3.07_4.07_17.4_0_0_3_3
Merc 450SL          17.3_8_275.8_180_3.07_3.73_17.6_0_0_3_3
Merc 450SLC           15.2_8_275.8_180_3.07_3.78_18_0_0_3_3
Cadillac Fleetwood   10.4_8_472_205_2.93_5.25_17.98_0_0_3_4
Lincoln Continental    10.4_8_460_215_3_5.424_17.82_0_0_3_4
Chrysler Imperial   14.7_8_440_230_3.23_5.345_17.42_0_0_3_4
Fiat 128              32.4_4_78.7_66_4.08_2.2_19.47_1_1_4_1
Honda Civic         30.4_4_75.7_52_4.93_1.615_18.52_1_1_4_2
Toyota Corolla       33.9_4_71.1_65_4.22_1.835_19.9_1_1_4_1
Toyota Corona       21.5_4_120.1_97_3.7_2.465_20.01_1_0_3_1
Dodge Challenger     15.5_8_318_150_2.76_3.52_16.87_0_0_3_2
AMC Javelin          15.2_8_304_150_3.15_3.435_17.3_0_0_3_2
Camaro Z28           13.3_8_350_245_3.73_3.84_15.41_0_0_3_4
Pontiac Firebird    19.2_8_400_175_3.08_3.845_17.05_0_0_3_2
Fiat X1-9              27.3_4_79_66_4.08_1.935_18.9_1_1_4_1
Porsche 914-2          26_4_120.3_91_4.43_2.14_16.7_0_1_5_2
Lotus Europa        30.4_4_95.1_113_3.77_1.513_16.9_1_1_5_2
Ford Pantera L        15.8_8_351_264_4.22_3.17_14.5_0_1_5_4
Ferrari Dino          19.7_6_145_175_3.62_2.77_15.5_0_1_5_6
Maserati Bora           15_8_301_335_3.54_3.57_14.6_0_1_5_8
Volvo 142E            21.4_4_121_109_4.11_2.78_18.6_1_1_4_2

Related StackOverflow question

Copy link

@everetr everetr commented Sep 5, 2017

I'm having the same issue. Running unite(data = vars, col = name, sep = " ") throws this exact error. But running unite(data = vars, col = name, V1:V6, sep = " "), where V1:V6 are column names of the vars tibble, runs without error and returns the desired output. ?unite documentation explicitly states that the ... argument can be left empty and, if so, unite() will select all variables.

Copy link

@abautistah abautistah commented Oct 11, 2017

Yeah same problem, trying to leave ... argument empty to use all columns but it is not working. Instead I got all colnames and used it as argument.

columnNames <- colnames(data)
unitedData <- data%>%unite(united, columNames ,sep=".")

@hadley hadley added the bug label Nov 15, 2017
@hadley hadley closed this in ebc2758 Nov 16, 2017
hadley added a commit that referenced this issue Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants