Defensive R Programming
Dr. Colin Gillespie
Jumping Rivers
.GlobalEnvls()n
# or did I want
N
library() gives you direct access to this package boxlibrary("dplyr") gives you direct access to the exported functions in dplyr## 238 exported functions
getNamespaceExports("dplyr")
:: to directly access a function## The filter function from dplyr
dplyr::filter
## The filter() function
stats::filter()
dplyr::filter()
filter() which version do I get?search() to the rescuesearch()
# [1] ".GlobalEnv" "package:dplyr" "package:stats"
# <Other packages>
Namespace clashes are more than just a pain
The conflicted package tries to make your function choice explicit
library("conflicted")
library("dplyr")
filter
#Error: [conflicted] `filter` found in 2 packages.
#Either pick the one you want with `::`
# * dplyr::filter
# * stats::filter
#Or declare a preference with `conflict_prefer()`
# * conflict_prefer("filter", "dplyr")
# * conflict_prefer("filter", "stats")
Defensive R Programming