From db5da41ea6c2f555beeb06564f1b6f6bdf024808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 6 Dec 2024 10:02:54 +0100 Subject: [PATCH 1/2] docs: typo fix --- R/join.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/join.R b/R/join.R index 315484c4a8..b3673d40f9 100644 --- a/R/join.R +++ b/R/join.R @@ -420,8 +420,8 @@ full_join.data.frame <- function(x, #' Filtering joins filter rows from `x` based on the presence or absence #' of matches in `y`: #' -#' * `semi_join()` return all rows from `x` with a match in `y`. -#' * `anti_join()` return all rows from `x` with**out** a match in `y`. +#' * `semi_join()` returns all rows from `x` with a match in `y`. +#' * `anti_join()` returns all rows from `x` with**out** a match in `y`. #' #' @param x,y A pair of data frames, data frame extensions (e.g. a tibble), or #' lazy data frames (e.g. from dbplyr or dtplyr). See *Methods*, below, for From e61360b21952a465d669bbf06b7ba33398d5bd88 Mon Sep 17 00:00:00 2001 From: DavisVaughan Date: Fri, 6 Dec 2024 17:35:25 +0000 Subject: [PATCH 2/2] Document --- man/filter-joins.Rd | 4 +- man/select.Rd | 156 +++----------------------------------------- 2 files changed, 10 insertions(+), 150 deletions(-) diff --git a/man/filter-joins.Rd b/man/filter-joins.Rd index 9193d7599b..f74c0ac383 100644 --- a/man/filter-joins.Rd +++ b/man/filter-joins.Rd @@ -79,8 +79,8 @@ An object of the same type as \code{x}. The output has the following properties: Filtering joins filter rows from \code{x} based on the presence or absence of matches in \code{y}: \itemize{ -\item \code{semi_join()} return all rows from \code{x} with a match in \code{y}. -\item \code{anti_join()} return all rows from \code{x} with\strong{out} a match in \code{y}. +\item \code{semi_join()} returns all rows from \code{x} with a match in \code{y}. +\item \code{anti_join()} returns all rows from \code{x} with\strong{out} a match in \code{y}. } } \section{Methods}{ diff --git a/man/select.Rd b/man/select.Rd index fb606cd440..f2fb5dda76 100644 --- a/man/select.Rd +++ b/man/select.Rd @@ -90,155 +90,15 @@ The following methods are currently available in loaded packages: \section{Examples}{ -Here we show the usage for the basic selection operators. See the -specific help pages to learn about helpers like \code{\link[=starts_with]{starts_with()}}. - -The selection language can be used in functions like -\code{dplyr::select()} or \code{tidyr::pivot_longer()}. Let's first attach -the tidyverse: - -\if{html}{\out{
}}\preformatted{library(tidyverse) - -# For better printing -iris <- as_tibble(iris) -}\if{html}{\out{
}} - -Select variables by name: - -\if{html}{\out{
}}\preformatted{starwars \%>\% select(height) -#> # A tibble: 87 x 1 -#> height -#> -#> 1 172 -#> 2 167 -#> 3 96 -#> 4 202 -#> # i 83 more rows - -iris \%>\% pivot_longer(Sepal.Length) -#> # A tibble: 150 x 6 -#> Sepal.Width Petal.Length Petal.Width Species name value -#> -#> 1 3.5 1.4 0.2 setosa Sepal.Length 5.1 -#> 2 3 1.4 0.2 setosa Sepal.Length 4.9 -#> 3 3.2 1.3 0.2 setosa Sepal.Length 4.7 -#> 4 3.1 1.5 0.2 setosa Sepal.Length 4.6 -#> # i 146 more rows +\if{html}{\out{
}}\preformatted{result <- rlang::with_options( + knitr::knit_child("man/rmd/select.Rmd"), + tibble.print_min = 4, + tibble.max_extra_cols = 8, + pillar.min_title_chars = 20, + digits = 2 +) +cat(result, sep = "\\n") }\if{html}{\out{
}} - -Select multiple variables by separating them with commas. Note how -the order of columns is determined by the order of inputs: - -\if{html}{\out{
}}\preformatted{starwars \%>\% select(homeworld, height, mass) -#> # A tibble: 87 x 3 -#> homeworld height mass -#> -#> 1 Tatooine 172 77 -#> 2 Tatooine 167 75 -#> 3 Naboo 96 32 -#> 4 Tatooine 202 136 -#> # i 83 more rows -}\if{html}{\out{
}} - -Functions like \code{tidyr::pivot_longer()} don't take variables with -dots. In this case use \code{c()} to select multiple variables: - -\if{html}{\out{
}}\preformatted{iris \%>\% pivot_longer(c(Sepal.Length, Petal.Length)) -#> # A tibble: 300 x 5 -#> Sepal.Width Petal.Width Species name value -#> -#> 1 3.5 0.2 setosa Sepal.Length 5.1 -#> 2 3.5 0.2 setosa Petal.Length 1.4 -#> 3 3 0.2 setosa Sepal.Length 4.9 -#> 4 3 0.2 setosa Petal.Length 1.4 -#> # i 296 more rows -}\if{html}{\out{
}} -\subsection{Operators:}{ - -The \code{:} operator selects a range of consecutive variables: - -\if{html}{\out{
}}\preformatted{starwars \%>\% select(name:mass) -#> # A tibble: 87 x 3 -#> name height mass -#> -#> 1 Luke Skywalker 172 77 -#> 2 C-3PO 167 75 -#> 3 R2-D2 96 32 -#> 4 Darth Vader 202 136 -#> # i 83 more rows -}\if{html}{\out{
}} - -The \code{!} operator negates a selection: - -\if{html}{\out{
}}\preformatted{starwars \%>\% select(!(name:mass)) -#> # A tibble: 87 x 11 -#> hair_color skin_color eye_color birth_year sex gender homeworld species -#> -#> 1 blond fair blue 19 male masculine Tatooine Human -#> 2 gold yellow 112 none masculine Tatooine Droid -#> 3 white, blue red 33 none masculine Naboo Droid -#> 4 none white yellow 41.9 male masculine Tatooine Human -#> # i 83 more rows -#> # i 3 more variables: films , vehicles , starships - -iris \%>\% select(!c(Sepal.Length, Petal.Length)) -#> # A tibble: 150 x 3 -#> Sepal.Width Petal.Width Species -#> -#> 1 3.5 0.2 setosa -#> 2 3 0.2 setosa -#> 3 3.2 0.2 setosa -#> 4 3.1 0.2 setosa -#> # i 146 more rows - -iris \%>\% select(!ends_with("Width")) -#> # A tibble: 150 x 3 -#> Sepal.Length Petal.Length Species -#> -#> 1 5.1 1.4 setosa -#> 2 4.9 1.4 setosa -#> 3 4.7 1.3 setosa -#> 4 4.6 1.5 setosa -#> # i 146 more rows -}\if{html}{\out{
}} - -\code{&} and \code{|} take the intersection or the union of two selections: - -\if{html}{\out{
}}\preformatted{iris \%>\% select(starts_with("Petal") & ends_with("Width")) -#> # A tibble: 150 x 1 -#> Petal.Width -#> -#> 1 0.2 -#> 2 0.2 -#> 3 0.2 -#> 4 0.2 -#> # i 146 more rows - -iris \%>\% select(starts_with("Petal") | ends_with("Width")) -#> # A tibble: 150 x 3 -#> Petal.Length Petal.Width Sepal.Width -#> -#> 1 1.4 0.2 3.5 -#> 2 1.4 0.2 3 -#> 3 1.3 0.2 3.2 -#> 4 1.5 0.2 3.1 -#> # i 146 more rows -}\if{html}{\out{
}} - -To take the difference between two selections, combine the \code{&} and -\code{!} operators: - -\if{html}{\out{
}}\preformatted{iris \%>\% select(starts_with("Petal") & !ends_with("Width")) -#> # A tibble: 150 x 1 -#> Petal.Length -#> -#> 1 1.4 -#> 2 1.4 -#> 3 1.3 -#> 4 1.5 -#> # i 146 more rows -}\if{html}{\out{
}} -} } \seealso{