Skip to content

docs: fix incorrect example in ?vec_duplicate#2169

Closed
LeonidasZhak wants to merge 1 commit into
r-lib:mainfrom
LeonidasZhak:docs/fix-vec-duplicate-example
Closed

docs: fix incorrect example in ?vec_duplicate#2169
LeonidasZhak wants to merge 1 commit into
r-lib:mainfrom
LeonidasZhak:docs/fix-vec-duplicate-example

Conversation

@LeonidasZhak

Copy link
Copy Markdown

docs: fix incorrect example in ?vec_duplicate

The example for equivalence with duplicated() used == instead of !=.
vec_duplicate_id(x) == seq_along(x) returns TRUE for first occurrences,
while duplicated(x) returns TRUE for duplicates (not first occurrences).

Fixes #1822.

Summary

Fix the example in ?vec_duplicate that claims to show equivalence with duplicated().

The example used vec_duplicate_id(x) == seq_along(x) but this returns TRUE for first occurrences (i.e., non-duplicates), while duplicated(x) returns TRUE for duplicates. The correct comparison is !=.

Changes

  • R/dictionary.R: Change == to != in the example comment
  • man/vec_duplicate.Rd: Regenerated from roxygen

Verification

library(vctrs)
x <- c(10, 10, 20, 30, 30, 40)
all.equal(vec_duplicate_id(x) != seq_along(x), duplicated(x))
#> TRUE

Fixes #1822.

The example for equivalence with `duplicated()` used `==` instead of `!=`.
`vec_duplicate_id(x) == seq_along(x)` returns TRUE for first occurrences,
while `duplicated(x)` returns TRUE for duplicates (not first occurrences).

Fixes r-lib#1822.
@DavisVaughan

Copy link
Copy Markdown
Member

Assuming this is the same as tidymodels/broom#1281 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typo in ?vec_duplicate

2 participants