Skip to content

Commit

Permalink
Document more complete compatibility with mutate
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Jul 10, 2024
1 parent ae5c9b9 commit 9e49d07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tests/testthat/test-compat-dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ test_that("Compatibility with dplyr::mutate(.keep)", {
expect_s3_class("linelist") %>%
expect_snapshot_warning()

x %>%
dplyr::mutate(speed = as.integer(speed)) %>%
expect_s3_class("linelist") %>%
tags() %>%
expect_identical(tags(x))

})

test_that("Compatibility with dplyr::relocate()", {
Expand Down
16 changes: 12 additions & 4 deletions vignettes/compat-dplyr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,25 @@ During operations on columns, linelist will:

### `dplyr::mutate()` ✓ (partial)

There is an incomplete compatibility with `dplyr::mutate()` in that:

- simple renames without any actual modification of the column don't update the tags. In this scenario, users should rather use `dplyr::rename()`
- in place column modifications cause tag losses
There is an incomplete compatibility with `dplyr::mutate()` in that simple renames without any actual modification of the column don't update the tags. In this scenario, users should rather use `dplyr::rename()`

Although `dplyr::mutate()` is not able to leverage to full power of linelist tags, linelist objects behave as expected the same way a data.frame would:

```{r}
# In place modification doesn't lose tags
x %>%
mutate(age = as.integer(age)) %>%
head()
# New columns don't affect existing tags
x %>%
mutate(major = age >= 18) %>%
head()
# .keep = "unused" generate expected tag loss conditions
x %>%
mutate(edad = age, .keep = "unused") %>%
head()
```

### `dplyr::pull()`
Expand Down

0 comments on commit 9e49d07

Please sign in to comment.