I'm trying to select columns from a data frame by the following code.
library(dplyr)
dv %>% select(LGA)
select(dv, LGA)
Both of them will fail with the error
Unable to find an inherited method for function ‘select’ for signature ‘"data.frame"’
But the following code will be fine.
dplyr::select(dv, LGA)
Is this a function confliction in packages?
All libraries imported are as the following.
library(jsonlite)
library(geojsonio)
library(dplyr)
library(ggmap)
library(geojson)
library(leaflet)
library(mapview)
library(RColorBrewer)
library(scales)
I'm new to R, so super confused how you guys deal with problems like this?
There's a great package that helps with package conflicts called conflicted.
If you type
search()
into your console, you'll see an ordered vector of packages called the "search list". When you callselect
, R searches through this "search path" and matches the first function calledselect
. When you calldplyr::select
you're calling it directly from the namespacedplyr
, so the function works as expected.Here's an example using
conflicted
. We'll load up raster and dplyr, which both have aselect
function.Now when we call
select
, we're prompted with the exact conflict: