context: Context dependent expressions

Description Usage data.table See Also Examples

Description

These functions return information about the "current" group or "current" variable, so only work inside specific contexts like summarise() and mutate().

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

data.table

If you're familiar with data.table:

See Also

See group_data() for equivalent functions that return values for all groups.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
df <- data.frame(
  g = sample(rep(letters[1:3], 1:3)),
  x = runif(6),
  y = runif(6),
  stringsAsFactors = FALSE
)
gf <- df %>% group_by(g)

gf %>% summarise(n = n())

gf %>% mutate(id = cur_group_id())
gf %>% summarise(row = cur_group_rows())
gf %>% summarise(data = list(cur_group()))
gf %>% summarise(data = list(cur_data()))
gf %>% summarise(data = list(cur_data_all()))

gf %>% mutate(across(everything(), ~ paste(cur_column(), round(.x, 2))))

poorman documentation built on March 28, 2021, 5:05 p.m.