The Unpacking Dot Operator

Provides a `.` object which can be used for unpacking assignments. For example, `.[rows, columns] <- dim(cars)` could be used to pull the number of rows and number of columns from `dim(cars)` into individual variables `rows` and `columns` in a single step.


dotty

R-CMD-check

Destructuring assignments in R with the . object.

Usage

library(dotty)

# extract number of rows, number of columns from mtcars
.[nr, nc] <- dim(mtcars)
c(nr, nc)
## [1] 32 11
# extract first, last element of vector
.[first, .., last] <- c(1, 2, 3, 4, 5)
c(first, last)
## [1] 1 5
# extract a value by name
.[beta = beta] <- list(alpha = 1, beta = 2, gamma = 3)
beta
## [1] 2
# unpack nested values
.[x, .[y, .[z]]] <- list(1, list(2, list(3)))
c(x, y, z)
## [1] 1 2 3
# split version components
.[major, minor, patch] <- getRversion()
c(major, minor, patch)
## [1] 4 4 1

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 so that variables usages in . expressions can be linted as though those were regular bindings / assignments.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("dotty")

0.1.0 by Kevin Ushey, 2 years ago


https://kevinushey.github.io/dotty/


Browse source code at https://github.com/cran/dotty


Authors: Kevin Ushey [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests codetools, testthat


Imported by keras3, quickr.

Depended on by nlsic.


See at CRAN