Skip to content

Commit cc87bbe

Browse files
committed
adding note about n, n_distinct, between and namespaces
1 parent 3532528 commit cc87bbe

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ To install the development version from GitHub:
6565
BiocManager::install("tidyomics/plyranges")
6666
```
6767

68+
# Namespace note
69+
70+
_plyranges_ re-exports `between()`, `n()`, and `n_distinct()` with
71+
Ranges-specific behaviour that differs from the `dplyr` originals; use
72+
`dplyr::n()` etc. if you need the originals. See the [Namespace
73+
considerations](https://tidyomics.github.io/plyranges/articles/an-introduction.html#namespace-considerations)
74+
section of the introduction vignette for details.
75+
6876
# Learning more
6977

7078
In addition to the two package vignettes, see the following for more informtion:

vignettes/an-introduction.Rmd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,32 @@ up on interesting hits from a combined RNA-seq and ATAC-seq analysis.
460460
- The [journal article](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-018-1597-8) ([preprint here](https://www.biorxiv.org/content/early/2018/05/23/327841)) has
461461
details about the overall philosophy and design of plyranges.
462462

463+
# Namespace considerations
464+
465+
`plyranges` re-exports three functions that otherwise exist in `dplyr` with
466+
different meanings:
467+
468+
- `between(x, y)` wraps `IRanges::pgap()` and returns the gap ranges between
469+
two paired Ranges objects. This is entirely distinct from `dplyr::between(x,
470+
left, right)`, which tests whether numeric values fall within a scalar
471+
interval.
472+
- `n()` is re-implemented to return group sizes for grouped Ranges objects
473+
(including grouped lists of ranges). `dplyr::n()` does the same for
474+
data frames.
475+
- `n_distinct()` is re-implemented to handle Bioconductor `List` objects via
476+
`lengths(unique(x))`. `dplyr::n_distinct()` operates on ordinary vectors.
477+
478+
Because `plyranges` is typically loaded after `dplyr`, these three names will
479+
resolve to the `plyranges` versions in your session. If you need the original
480+
`dplyr` behaviour, call it explicitly: `dplyr::n()`, `dplyr::n_distinct()`,
481+
or `dplyr::between()`.
482+
483+
Note that for the standard `dplyr` verbs — `mutate()`, `filter()`,
484+
`summarise()`, `select()`, `arrange()`, and `group_by()``plyranges`
485+
registers S4 methods so that these verbs work directly on `GRanges` and
486+
`IRanges` objects without any renaming. Therefore `mutate(<GRanges>)` works
487+
and is the same as `dplyr::mutate(<GRanges>)`.
488+
463489
# Session information
464490

465491
```{r}

0 commit comments

Comments
 (0)