0

What's the difference to use the select() directly, and use dplyr::select() in R? If we use the dplyr::select(), does it mean I do not need to library (dplyr)? If they are same, why do some people prefer to use dplyr::select()?

  • 1
    If you have loaded any other library that have the same function `select` and if that masks the `select` from `dplyr`, then using `dplyr::select` gets you the function characteristics of `dplyr` instead of the other library. One common example is `mutate` which is found in `dplyr` and `plyr`. When an user loads both libraries and if the `dplyr::mutate` is masked by `plyr::mutate` it can create issues in the output – akrun Dec 19 '18 at 06:02

2 Answers2

1

library::function is just a way to specify which library to use the function from. Several functions can appear in more than one library, so one if you activate both libraries, one function masks another. (It is always written in a compilation log after library() function.)

aschmsu
  • 302
  • 1
  • 9
0

library::select() is similar to the select statement in sql but the difference is while working for many packages it may be chances to conflict one package with another. Also without loading the package we can mention the library with function.

library::select() ##without loading the library,just u r using the select function from dplyr

Ex:try to run library(dplyr) first and library(tidyverse) then u will see some warning messages as conflicts.

library(dplyr)
library(tidyverse)
── Attaching packages ────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.1.0     ✔ readr   1.3.0
✔ tibble  1.4.2     ✔ purrr   0.2.5
✔ tidyr   0.8.2     ✔ stringr 1.3.1
✔ ggplot2 3.1.0     ✔ forcats 0.3.0
── Conflicts ───────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ plyr::arrange()       masks dplyr::arrange()
✖ data.table::between() masks dplyr::between()
✖ purrr::compact()      masks plyr::compact()
✖ plyr::count()         masks dplyr::count()
✖ plyr::failwith()      masks dplyr::failwith()
✖ dplyr::filter()       masks stats::filter()
✖ data.table::first()   masks dplyr::first()
✖ plyr::id()            masks dplyr::id()
✖ dplyr::lag()          masks stats::lag()
✖ data.table::last()    masks dplyr::last()
✖ plyr::mutate()        masks dplyr::mutate()
✖ plyr::rename()        masks dplyr::rename()
✖ plyr::summarise()     masks dplyr::summarise()
✖ plyr::summarize()     masks dplyr::summarize()
✖ purrr::transpose()    masks data.table::transpose()
sai saran
  • 737
  • 9
  • 32