When I use the select function from dplyr, it doesn't work and gives me an error stating that the column names that I want to select are unused arguments. However, if I specify dplyr before the function call like s: "dplyr::select" then it works as normal:
Here is a sample df:
sampledf <- structure(list(CRN = c(5497L, 6515L, 7248L, 36956L, 37021L),
varA = structure(c(2L, 2L, 2L, 2L, 2L), .Label = c("A",
"B"), class = "factor"), varB = c(NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), VarC = c(NA, NA,
NA, NA, 2L), varD = c(NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), varE = c(1L, 1L, 4L, NA, NA)), .Names = c("CRN",
"varA", "varB", "varC", "varD", "varE"), row.names = c(NA, 5L), class = "data.frame")
this produces the error:
sample_error <- select(sampledf, varA)
Error in select(sampledf, varA) : unused argument (varA)
and this works:
sample_working <- dplyr::select(sampledf, varA)
version
version _
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 4.0
year 2017
month 04
day 21
svn rev 72570
language R
version.string R version 3.4.0 (2017-04-21) nickname You Stupid Darkness
And here is the session info:
sessionInfo()
R version 3.4.0 (2017-04-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)
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] readxl_1.0.0 bindrcpp_0.2 doBy_4.5-15 reshape2_1.4.2 ltm_1.0-0 > polycor_0.7-9 msm_1.6.4
[8] MASS_7.3-47 glmnet_2.0-10 foreach_1.4.3 Matrix_1.2-9 caret_6.0-76 lattice_0.20-35 dplyr_0.7.2
[15] purrr_0.2.3 readr_1.1.1 tidyr_0.6.3 tibble_1.3.3 > > > > > > ggplot2_2.2.1 tidyverse_1.1.1 openxlsx_4.0.17loaded via a namespace (and not attached): [1] Rcpp_0.12.11 lubridate_1.6.0 mvtnorm_1.0-6 assertthat_0.2.0 > psych_1.7.5 R6_2.2.2
[7] cellranger_1.1.0 plyr_1.8.4 MatrixModels_0.4-1 stats4_3.4.0 > httr_1.3.1 rlang_0.1.1
[13] lazyeval_0.2.0 minqa_1.2.4 SparseM_1.77 car_2.1-4 > nloptr_1.0.4 labeling_0.3
[19] splines_3.4.0 lme4_1.1-13 stringr_1.2.0 foreign_0.8-67 munsell_0.4.3 broom_0.4.2
[25] compiler_3.4.0 modelr_0.1.1 pkgconfig_2.0.1 mnormt_1.5-5 mgcv_1.8-17 nnet_7.3-12
[31] expm_0.999-2 codetools_0.2-15 ModelMetrics_1.1.0 grid_3.4.0 nlme_3.1-131 jsonlite_1.5
[37] gtable_0.2.0 magrittr_1.5 scales_0.4.1 stringi_1.1.5 xml2_1.1.1 iterators_1.0.8
[43] tools_3.4.0 forcats_0.2.0 glue_1.1.0 hms_0.3 survival_2.41-3 parallel_3.4.0
[49] pbkrtest_0.4-7 colorspace_1.3-2 rvest_0.3.2 bindr_0.1 haven_1.1.0 quantreg_5.33
It is likely that you are either using a package besides dplyr that also has a select() function or you just forgot to load the dplyr package with library(dplyr) .
The select() function of dplyr package is used to select variable names from the R data frame. Use this function if you wanted to select the data frame variables by index or position.
The “unused argument error in r” message occurs when you are using a function in R. It occurs when an argument used does not match the arguments in the argument list. This is particularly true when a different argument is added than what is in the list.
I had the same issue and it was caused by name clash with another package. Use: dplyr::select
to specify the package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With