Package 'navigatr'

Title: Navigation Menu for Pipe-Friendly Data Processing
Description: Provides a navigation menu to enable pipe-friendly data processing for hierarchical data structures. By activating the menu items, you can perform operations on each item while maintaining the overall structure in attributes.
Authors: Mizuki Uchida [aut, cre]
Maintainer: Mizuki Uchida <[email protected]>
License: MIT + file LICENSE
Version: 0.2.1
Built: 2024-11-10 03:29:12 UTC
Source: https://github.com/uchidamizuki/navigatr

Help Index


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)

Set items

Description

Set items

Usage

itemise(.data, ...)

itemize(.data, ...)

Arguments

.data

A navigatr_nav_input object.

...

Key-value pairs.

Value

A navigatr_nav_input object.


Deprecated functions

Description

Deprecated functions

Usage

new_menu(
  key = character(),
  value = list(),
  attrs = NULL,
  ...,
  class = character()
)

Arguments

key

A unique character vector.

value

A list of values corresponding to the keys.

attrs

A data frame for additional attributes of items (an empty data frame by default). When an item becomes active, the attrs will be added to its attributes.

...

Additional arguments passed to vctrs::new_data_frame().

class

A character vector of subclasses passed to vctrs::new_data_frame().

Value

A navigatr_nav_menu object, a subclass of class data.frame.


Build a new input form

Description

To create a new input form, give new_nav_input() a unique key and the corresponding list of values. By default, the values are empty characters. Each line shows the menu items (keys on the left, value summaries on the right). The summaries are pillar::obj_sum outputs, so you can change the printing methods. Each menu item can be changed by itemise().

Usage

new_nav_input(
  key = character(),
  value = list(character()),
  ...,
  class = character()
)

Arguments

key

A unique character vector.

value

A list of values corresponding to the keys. By default, the values are empty characters.

...

Additional arguments passed to vctrs::new_data_frame().

class

A character vector of subclasses passed to vctrs::new_data_frame().

Value

A navigatr_nav_input object, a subclass of class data.frame.

See Also

itemise()


Build a new menu

Description

To build a new menu, give new_nav_menu() unique keys and a list of their corresponding values. Each line shows the menu items (keys on the left, value summaries on the right). The summaries are pillar::obj_sum outputs, so you can change the printing methods. Each menu item can be accessed by activate().

Usage

new_nav_menu(
  key = character(),
  value = list(data.frame()),
  attrs = NULL,
  ...,
  class = character()
)

Arguments

key

A unique character vector.

value

A list of values corresponding to the keys.

attrs

A data frame for additional attributes of items (an empty data frame by default). When an item becomes active, the attrs will be added to its attributes.

...

Additional arguments passed to vctrs::new_data_frame().

class

A character vector of subclasses passed to vctrs::new_data_frame().

Value

A navigatr_nav_menu object, a subclass of class data.frame.

See Also

activate()

Examples

library(dplyr)

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

# You can also build a nested menu
bands <- new_nav_menu(key = c("key1", "key2"),
                      value = list(band, band))
bands

Rename key names

Description

Rename key names

Usage

rekey(.data, ...)

## S3 method for class 'navigatr_nav'
rekey(.data, ...)

## S3 method for class 'navigatr_item'
rekey(.data, ...)

rekey_with(.data, .fn, .keys = tidyselect::everything(), ...)

Arguments

.data

For rekey(), A navigatr_nav or navigatr_item object. For rekey_with(), A navigatr_nav object.

...

For navigatr_nav objects, use new_name = old_name. For navigatr_item objects, a scalar character of the new key name.

.fn

A function used to transform the selected .keys.

.keys

Keys to rename; defaults to all keys.

Value

A navigatr_nav or navigatr_item object.