Activates a menu item with the same syntax as dplyr::pull()
.
Activating a menu item allows you to perform operations on the active item.
activate()
turns a navigatr_nav_menu
object into an navigatr_item
object, and deactivate()
turns it back.
Usage
activate(.data, ..., .add = FALSE)
# S3 method for navigatr_nav_menu
activate(.data, ..., .add = FALSE)
# S3 method for navigatr_item
activate(.data, ..., .add = FALSE)
deactivate(x, ..., deep = TRUE)
# S3 method for navigatr_nav_menu
deactivate(x, ..., deep = TRUE)
# S3 method for navigatr_item
deactivate(x, ..., deep = TRUE)
Arguments
- .data
A
navigatr_nav_menu
object.- ...
In
activate()
, one or more variables passed todplyr::pull()
. Indeactivate()
, unused (for extensibility).- .add
Whether to add new variables to the path indices. If
FALSE
(default value), the menu will be deactivated first bydeactivate()
.- x
A
navigatr_nav_menu
object.- deep
If
TRUE
(default value), deactivate recursively.
Value
In activate()
, An navigatr_item
object.
If it inherits from class navigatr_nav_menu
, the menu will be displayed
hierarchically.
Otherwise, the active data will be displayed.
In deactivate()
, A navigatr_nav_menu
object.
Examples
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
mn1 <- new_nav_menu(key = c("band_members", "band_instruments"),
value = list(band_members, band_instruments))
mn1 |>
activate(band_members) |>
filter(band == "Beatles")
#> # ☒ band_members: tibble [2 × 2]
#> # ☐ band_instruments: tibble [3 × 2]
#> #
#> # A tibble: 2 × 2
#> name band
#> <chr> <chr>
#> 1 John Beatles
#> 2 Paul Beatles
# Items can also be specified as integers
mn1 |>
activate(2)
#> # ☐ band_members: tibble [3 × 2]
#> # ☒ band_instruments: tibble [3 × 2]
#> #
#> # A tibble: 3 × 2
#> name plays
#> <chr> <chr>
#> 1 John guitar
#> 2 Paul bass
#> 3 Keith guitar
mn1 |>
activate(-1) |>
deactivate()
#> # ☐ band_members: tibble [3 × 2]
#> # ☐ band_instruments: tibble [3 × 2]
#> #
#> # Please `activate()`.
# To activate items in a nested menu, specify multiple variables
mn2 <- new_nav_menu(key = c("key1", "key2"),
value = list(mn1, mn1))
mn2 |>
activate(key1, band_members)
#> # ☒ key1: nav_menu [2]
#> # ☒ band_members: tibble [3 × 2]
#> # ☐ band_instruments: tibble [3 × 2]
#> # ☐ key2: nav_menu [2]
#> #
#> # A tibble: 3 × 2
#> name band
#> <chr> <chr>
#> 1 Mick Stones
#> 2 John Beatles
#> 3 Paul Beatles