1

I am encountering a strange problem in using packages MASS and dplyr together in R using RStudio. The following code

library(dplyr)
select(iris, starts_with("Petal"))

works and gives me the right output. But if I try to load MASS package and use the same code

library(MASS)
library(dplyr)
select(iris, starts_with("Petal"))

I get an error

select(iris, starts_with("Petal"))
Error in select(iris, starts_with("Petal")) : 
  unused argument (starts_with("Petal"))

Is there a known issue with using dplyr with MASS in RStudio. I am loading dplyr after MASS so as not to mask the select from dplyr. I have un-installed and re-installed my RStudio also, but the error persists.

I am using R Version 3.2.2, MASS version - 7.3-45 and dplyr version 0.5.0

Any help would be highly appreciated!

sn248

joran
  • 169,992
  • 32
  • 429
  • 468
Satya
  • 1,708
  • 1
  • 15
  • 39
  • 5
    For future reference, RStudio != R. RStudio is "just" an IDE, it doesn't really impact what's going on with your R code. So re-installing RStudio (and the RStudio tag) were unnecessary here. – joran Mar 27 '17 at 16:35
  • Thanks, as I was typing this question - a similar question popped up in Stackoverflow which recommended un/re-installing the IDE. So, I tried it and mentioned that I have already tried that step. – Satya Mar 27 '17 at 16:49
  • In the chunk that gives you the error... shouldn't you load dplyr before MASS to get that error? – Dason Mar 27 '17 at 17:28
  • That was my question, even though I was loading `dplyr` after `MASS`, I was getting an error, don't know why. – Satya Mar 27 '17 at 18:23

1 Answers1

7

Both packages have a select function.

Use dplyr::select() or MASS::select() as needed to prevent errors.

Another popular conflict is the dplyr::filter vs signal::filter.

If you don't want to type the package name every time you can type once dselect <- dplyr::select and then use dselect all the time instead.

zeehio
  • 4,023
  • 2
  • 34
  • 48
  • 4
    Today's episode of "tidyverse considered harmful" as it stomps over base R and recommended packages. – Dirk Eddelbuettel Mar 27 '17 at 16:44
  • thanks, somehow the `select` now works, but your solution is helpful and should work every time – Satya Mar 27 '17 at 16:47
  • If I had created a general purpose package (such as dplyr) and I knew about signal and MASS I would have avoided the conflict, choosing something like `filter_rows` and `filter_columns` instead of `filter` and `select`. But I would not say that there is a daily episode of "tidyverse considered harmful" because of this... the tidyverse is not perfect but its benefits outweight the downsides from my humble point of view... – zeehio Mar 27 '17 at 17:12
  • 3
    @SN248 I think it "works" now because the code you posted had the library calls in the wrong order and now you're running the code in the order that you posted here. – Dason Mar 27 '17 at 17:33