Skip to content

Commit

Permalink
suggested rename in compatibility.Rmd
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheaphy committed Nov 13, 2024
1 parent 8a22685 commit 870524b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions vignettes/compatibility.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ rle <- function(x) {
}
n <- length(x)
if (n == 0L) {
new_rle(integer(), x)
rle2(integer(), x)
} else {
y <- x[-1L] != x[-n]
i <- c(which(y | is.na(y)), n)
new_rle(diff(c(0L, i)), x[i])
rle2(diff(c(0L, i)), x[i])
}
}
new_rle <- function(lengths, values) {
rle2 <- function(lengths, values) {
structure(
list(
lengths = lengths,
Expand All @@ -97,7 +97,7 @@ There are two ways to convert this to S7.
You could keep the structure exactly the same, using a `list` as the underlying data structure and using a constructor to enforce the structure:

```{r}
new_rle <- new_class("rle",
rle2 <- new_class("rle",
parent = class_list,
constructor = function(lengths, values) {
new_object(list(lengths = lengths, values = values))
Expand All @@ -109,7 +109,7 @@ rle(1:10)
Alternatively you could convert it to the most natural representation using S7:

```{r}
new_rle <- new_class("rle", properties = list(
rle2 <- new_class("rle", properties = list(
lengths = class_integer,
values = class_atomic
))
Expand All @@ -118,7 +118,7 @@ new_rle <- new_class("rle", properties = list(
To allow existing methods to work you'll need to override `$` to access properties instead of list elements:

```{r}
method(`$`, new_rle) <- prop
method(`$`, rle2) <- prop
rle(1:10)
```

Expand Down

0 comments on commit 870524b

Please sign in to comment.