rpackageconflicting-libraries

R how to select functions between conflicting libraries


When writing scripts on R,

I had trouble choosing functions with overlapping packages.

For example,

library(dplyr)
library(tidyverse)
~~~~~

And in the console,

-- Conflicts ---------------------------- tidyverse_conflicts() ---
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
~~~~

How can I select the right functions? For example, I want "filter()" from dplyr and lag() from stats.

*p.s. I don't want to write library() every time


Solution

  • If you don't want to use dplyr::filter every time, we can use the {conflicted} package.

    library(dplyr)
    conflict_prefer("filter", "dplyr")