dotdot"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

This package proposes an enhanced assignment using the shorthand ...

It's meant to :

library(dotdot)
x <- y <- iris
x$Sepal.Length[5] <- x$Sepal.Length[5] + 3
y$Sepal.Length[5] := .. + 3
identical(x,y)

z <- factor(letters[1:3])
levels(z) := c(.., "level4")
z

It can help to think about the .. as the : of the := symbol laid horizontally.

Integration with data.table, tidyverse and other packages using :=

The operator := is used by prominent packages data.table and rlang (mostly through tidyverse functions), but they only use it to parse expressions, due to its convenient operator precedence. It's not actually called.

Thus dotdot is completely tidyverse and data.table compatible, and some adhoc adjustments were made so it works when the latter are attached after dotdot.

In the rare case in which the user would attach another package containing :=, dotdot_first() will move back dotdot at the first position of the search path.

Comparison with magrittr's %<>%

The package magrittr contains the operator %<>% which share important similarities with :=.

The calls iris$Sepal.Length %<>% log() and iris$Sepal.Length := log(..) indeed have the same effect.

The operator precedence is different however, which makes dotdot arguably better suited outside of pipe chains, for instance iris$Sepal.Length[5] := 2*.. + 3 would have to be written iris$Sepal.Length[5] %<>% multiply_by(2) %>% add(3) or iris$Sepal.Length[5] %<>% {2*. + 3} using magrittr.

Furthermore magrittr is more complex in the way it deals with environments while dotdot makes straightforward substitutions, so x := substitute(..) works and doesn't have a magrittr equivalent.



Try the dotdot package in your browser

Any scripts or data that you put into this service are public.

dotdot documentation built on May 2, 2019, 3:33 p.m.