-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
53 lines (38 loc) · 1.19 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
title: dotty
output: github_document
---
<!-- badges: start -->
[![R-CMD-check](https://github.com/kevinushey/dotty/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kevinushey/dotty/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
Destructuring assignments in R with the `.` object.
### Usage
```{r}
library(dotty)
# extract number of rows, number of columns from mtcars
.[nr, nc] <- dim(mtcars)
c(nr, nc)
# extract first, last element of vector
.[first, .., last] <- c(1, 2, 3, 4, 5)
c(first, last)
# extract a value by name
.[beta = beta] <- list(alpha = 1, beta = 2, gamma = 3)
beta
# unpack nested values
.[x, .[y, .[z]]] <- list(1, list(2, list(3)))
c(x, y, z)
# split version components
.[major, minor, patch] <- getRversion()
c(major, minor, patch)
```
### R CMD check
If you'd like to use `dotty` in your CRAN package, you can avoid
`R CMD check` warnings by including a file called `R/zzz.R` with the contents:
```
.onLoad <- function(libname, pkgname) {
dotty::dotify()
}
```
This function patches [codetools](https://cran.r-project.org/package=codetools)
so that variables usages in `.` expressions can be linted as though those
were regular bindings / assignments.