From adbdbfca5a67d2449267f7b8d1d7d8dc220aa84c Mon Sep 17 00:00:00 2001 From: Jim Gardner <90831652+jimgar@users.noreply.github.com> Date: Sun, 23 Jul 2023 15:51:34 +0100 Subject: [PATCH] Update packages.Rmd Because it is one of the fundamental benefits of the operator, I thought it would be worth putting in a little bit that explains `::` can be used to prevent namespace conflicts. It seems reasonable, because I think novice R users could otherwise believe that using `conflicted` is the only way to work. But this is just a suggestion. --- episodes/packages.Rmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/episodes/packages.Rmd b/episodes/packages.Rmd index 7e01b39b..cdec9f06 100644 --- a/episodes/packages.Rmd +++ b/episodes/packages.Rmd @@ -238,7 +238,9 @@ As you may imagine, this can cause confusion. For example, the `filter()` function appears in both the `stats` package and the `dplyr` package, but does completely different things in each. This is a **namespace conflict**: how do we know which `filter()` we are talking about? -The `conflicted` package can help prevent such confusion by stopping you if you try to use an ambiguous function, and help you be explicit about which package to use. +One solution we have covered already is using the `::` notation when calling functions. This is because writing `dplyr::filter()` specifies that you are using `filter()` from the `dplyr` namespace. The tradeoff to this approach is verbosity, meaning more typing and reading. + +An alternative to `::` is to use the `conflicted` package. It can help prevent confusion by stopping you if you try to use an ambiguous function, and help you be explicit about which package to use. We don't have time to cover the details here, but you can read more about how to use `conflicted` at its [website](https://conflicted.r-lib.org/). When you use `conflicted`, you will typically run a series of commands to explicitly resolve namespace conflicts, like `conflicts_prefer(dplyr::filter)` (this would tell R that we want to use `filter` from `dplyr`, not `stats`).