Skip to content

Commit

Permalink
CRAN update 0.9.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicChr committed May 7, 2024
1 parent 741cfcb commit aeca74e
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 113 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cheapr
Title: Simple Functions to Save Time and Memory
Version: 0.9.0.9000
Version: 0.9.1
Authors@R:
person("Nick", "Christofides", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9743-7342"))
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cheapr (Development version)
# cheapr 0.9.1

* New function `recycle` to help recycle R objects to a common size.

Expand Down
22 changes: 16 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,32 @@ lag_(1:10, 3) # Lag(3)
lag_(1:10, -3) # Lead(3)
# Using an example from data.table
DF <- data.frame(year=2010:2014, v1=runif(5), v2=1:5, v3=letters[1:5])
library(data.table)
dt <- data.table(year=2010:2014, v1=runif(5), v2=1:5, v3=letters[1:5])
# Similar to data.table::shift()
lag_(DF, 1) # Lag
lag_(DF, -1) # Lead
lag_(dt, 1) # Lag
lag_(dt, -1) # Lead
```

With `lag_` we can update variables by reference, including entire data frames

```{r}
# At the moment, shift() cannot do this
lag_(DF, set = TRUE)
lag_(dt, set = TRUE)
dt # Was updated by reference
```

DF # Was updated by reference
`lag2_` is a more generalised variant that supports vectors of lags,
custom ordering and run lengths.

```{r}
lag2_(dt, order = 5:1) # Reverse order lag (same as lead)
lag2_(dt, -1) # Same as above
lag2_(dt, c(1, -1)) # Alternating lead/lag
lag2_(dt, c(-1, 0, 0, 0, 0)) # Lead e.g. only first row
```


Expand Down
Loading

0 comments on commit aeca74e

Please sign in to comment.