Skip to contents

Path-based access and manipulation for R lists

Path-based access and manipulation for R lists

Details

The slash class provides tools for working with hierarchical R lists using path-like strings (e.g., "a/b/c"). Rather than creating a new data structure, it adds convenient path-based access methods to standard R lists, supporting: - Both named and numeric (1-based) indexing - Strict mode for error checking - Various operations for list manipulation

Methods


Method new()

Create a new slash object

Usage

slash$new(data = list(), strict = FALSE)

Arguments

data

Initial data (must be a list)

strict

If TRUE, attempts to access non-existent paths will error

Returns

A new `slash` object


Method get()

Get value at specified path

Usage

slash$get(path = NULL, default = NULL)

Arguments

path

Path to the element (e.g., "a/b/c" or "1/2/3")

default

Value to return if path doesn't exist (NULL by default)

Returns

The value at the specified path, or default if not found


Method set()

Set value at specified path

Usage

slash$set(path, value)

Arguments

path

Path to the element

value

Value to set

Returns

The slash object (invisibly) for chaining


Method exists()

Check if path exists

Usage

slash$exists(path)

Arguments

path

Path to check

Returns

TRUE if path exists, FALSE otherwise


Method delete()

Delete element at specified path

Usage

slash$delete(path)

Arguments

path

Path to delete

Returns

The slash object (invisibly) for chaining


Method clear()

Clear all data

Usage

slash$clear()

Returns

The slash object (invisibly) for chaining


Method get_all()

Get all data as a list

Usage

slash$get_all()

Returns

The complete data structure


Method print()

Print summary of slash object

Usage

slash$print(show_full = FALSE)

Arguments

show_full

If TRUE, shows full structure (FALSE by default)


Method print_list()

Print list structure at path

Usage

slash$print_list(path = NULL)

Arguments

path

Path to print (NULL for root)


Method list_paths()

List all available paths

Usage

slash$list_paths()

Returns

Character vector of all paths in the data structure


Method is_strict()

Check if in strict mode

Usage

slash$is_strict()

Returns

TRUE if in strict mode, FALSE otherwise


Method set_strict()

Set strict mode

Usage

slash$set_strict(strict)

Arguments

strict

Logical value for strict mode

Returns

The slash object (invisibly) for chaining


Method filter_paths()

Filter paths by regex pattern

Usage

slash$filter_paths(pattern, ignore_case = FALSE)

Arguments

pattern

Regex pattern to match against paths

ignore_case

TRUE to ignore cases, FALSE otherwise. Defaults to FALSE.

Returns

Character vector of matching paths


Method print_tree()

Print a tree-like diagram of the list structure

Usage

slash$print_tree(path = NULL)

Arguments

path

Optional starting path (NULL for root)


Method clone()

The objects of this class are cloneable with this method.

Usage

slash$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.