Skip to content

Commit

Permalink
Tweak for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Aug 21, 2024
1 parent 3663c15 commit 216bbc7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dependencies-in-practice.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,10 @@ export(count)
...
```

Now imagine that your package implements a method for `count()` for a class you "own" (not `data.frame`) but a generic that you "don't own".
Now imagine that your package implements a method for `count()` for a class you "own" (not `data.frame`).
A good example is the dbplyr package, which implements dplyr's `count()` generic for dbplyr's `tbl_lazy` class.

In this case, `@export` will not work because it assumes the `count()` generic is included or imported in the dbplyr NAMESPACE, so instead we need to use `@exportS3Method`, providing the precise generic that we're providing a method for.
In this case, `@export` will not work because it assumes the `count()` generic is included or imported in the dbplyr `NAMESPACE`, so instead we need to use `@exportS3Method`, providing the precise generic that we're providing a method for.

```{r}
#| eval: false
Expand All @@ -693,9 +693,9 @@ In `NAMESPACE`, we have:
S3method(dplyr::count,tbl_lazy)
```

This also works for generics for packages that are suggested dependencies, e.g. where the glue package implements a method for testthat's `compare()` generic: glue lists testthat as only a suggested dependency, so (as of R 3.6.0) R will conditionally register the method `compare.glue()` when both the testthat and the glue packages are loaded.
This also works for generics from packages that are suggested dependencies, e.g. where the glue package implements a method for testthat's `compare()` generic: glue lists testthat as only a suggested dependency, so (as of R 3.6.0) R will conditionally register the method `compare.glue()` when both the testthat and the glue packages are loaded.

dbplyr also provides methods for various generics provided by the base package, such as `dim()` and `names()` - in this case, we can still use `@export` since the generics are available in the package NAMESPACE.
dbplyr also provides methods for various generics provided by the base package, such as `dim()` and `names()` - in this case, we can still use `@export` since the generics are available in the package `NAMESPACE`.

In `dbplyr/R/tbl_lazy.R`, we have:

Expand Down

0 comments on commit 216bbc7

Please sign in to comment.