|
9 | 9 | output: |
10 | 10 | blogdown::html_page: |
11 | 11 | toc: true |
| 12 | +images: |
| 13 | + - selection-ambiguity.png |
12 | 14 | --- |
13 | 15 |
|
14 | 16 |
|
15 | 17 | <div id="TOC"> |
16 | 18 | <ul> |
17 | | -<li><a href="#intro">Intro</a></li> |
18 | | -<li><a href="#problem-1-symbols-vs.-strings-with-names">Problem 1: Symbols vs. strings with names</a></li> |
19 | | -<li><a href="#problem-2-passing-column-names-as-arguments-to-custom-functions">Problem 2: Passing column names as arguments to custom functions</a></li> |
20 | | -<li><a href="#problem-3-dynamic-columns-in-purrr-formulas-in-across">Problem 3: Dynamic columns in purrr formulas in <code>across</code></a></li> |
21 | | -<li><a href="#summary-next-steps">Summary & Next Steps</a></li> |
22 | | -<li><a href="#dive-deeper-resources-for-the-curious-minds">Dive Deeper: Resources for the Curious Minds:</a></li> |
| 19 | +<li><a href="#intro" id="toc-intro">Intro</a></li> |
| 20 | +<li><a href="#problem-1-symbols-vs.-strings-with-names" id="toc-problem-1-symbols-vs.-strings-with-names">Problem 1: Symbols vs. strings with names</a></li> |
| 21 | +<li><a href="#problem-2-passing-column-names-as-arguments-to-custom-functions" id="toc-problem-2-passing-column-names-as-arguments-to-custom-functions">Problem 2: Passing column names as arguments to custom functions</a></li> |
| 22 | +<li><a href="#problem-3-dynamic-columns-in-purrr-formulas-in-across" id="toc-problem-3-dynamic-columns-in-purrr-formulas-in-across">Problem 3: Dynamic columns in purrr formulas in <code>across</code></a></li> |
| 23 | +<li><a href="#summary-next-steps" id="toc-summary-next-steps">Summary & Next Steps</a></li> |
| 24 | +<li><a href="#dive-deeper-resources-for-the-curious-minds" id="toc-dive-deeper-resources-for-the-curious-minds">Dive Deeper: Resources for the Curious Minds:</a></li> |
23 | 25 | </ul> |
24 | 26 | </div> |
25 | 27 |
|
@@ -70,15 +72,18 @@ <h2>Problem 1: Symbols vs. strings with names</h2> |
70 | 72 | ## # Now: |
71 | 73 | ## data %>% select(all_of(my_variables)) |
72 | 74 | ## |
73 | | -## See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.</code></pre> |
| 75 | +## See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>. |
| 76 | +## This warning is displayed once every 8 hours. |
| 77 | +## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was |
| 78 | +## generated.</code></pre> |
74 | 79 | <pre><code>## Sepal.Length Sepal.Width |
75 | 80 | ## 1 5.1 3.5 |
76 | 81 | ## 2 4.9 3.0 |
77 | 82 | ## 3 4.7 3.2 |
78 | 83 | ## 4 4.6 3.1 |
79 | 84 | ## 5 5.0 3.6</code></pre> |
80 | 85 | <p>This generates a warning. Given the tidyverse’s informative error messages, it’s wise to pay heed. Directly supplying can be ambiguous – imagine having a column named <code>my_variable</code>. Which should be selected if we have both the column and the external variable?</p> |
81 | | -<p><img src="images/selection-ambiguity.png" alt="Diagram showing the dillema that dplyr is faced with when we torment it with ambiguous selections." /> |
| 86 | +<p><img src="selection-ambiguity.png" alt="Diagram showing the dillema that dplyr is faced with when we torment it with ambiguous selections." /> |
82 | 87 | To ensure clarity, dplyr authors suggest using dplyr::all_of(), which explicitly converts a name vector into symbols, resolving any ambiguities.</p> |
83 | 88 | <pre class="r"><code>iris %>% |
84 | 89 | select(all_of(my_variables))</code></pre> |
|
0 commit comments