activate: Activate or deactivate a menu item

View source: R/activate.R

activateR Documentation

Activate or deactivate a menu item

Description

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 class 'navigatr_nav_menu'
activate(.data, ..., .add = FALSE)

## S3 method for class 'navigatr_item'
activate(.data, ..., .add = FALSE)

deactivate(x, ..., deep = TRUE)

## S3 method for class 'navigatr_nav_menu'
deactivate(x, ..., deep = TRUE)

## S3 method for class 'navigatr_item'
deactivate(x, ..., deep = TRUE)

Arguments

.data

A navigatr_nav_menu object.

...

In activate(), one or more variables passed to dplyr::pull(). In deactivate(), unused (for extensibility).

.add

Whether to add new variables to the path indices. If FALSE (default value), the menu will be deactivated first by deactivate().

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)

mn1 <- new_nav_menu(key = c("band_members", "band_instruments"),
                    value = list(band_members, band_instruments))

mn1 |>
  activate(band_members) |>
  filter(band == "Beatles")

# Items can also be specified as integers
mn1 |>
  activate(2)

mn1 |>
  activate(-1) |>
  deactivate()

# 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)


navigatr documentation built on March 31, 2023, 9:42 p.m.