safe_extract: Safely Extract Elements from a List

View source: R/pathway_annotation.R

safe_extractR Documentation

Safely Extract Elements from a List

Description

Safely extracts elements from a list, returning NA if the extraction fails

Usage

safe_extract(list, field, index = 1)

Arguments

list

A list object from which to extract elements

field

The name of the field to extract from the list

index

The index position to extract from the field. Default is 1

Value

The extracted element if successful, NA if extraction fails

Examples

# Create a sample list
my_list <- list(
  a = list(x = 1:3),
  b = list(y = 4:6)
)

# Extract existing element
safe_extract(my_list, "a", 1)

# Extract non-existing element (returns NA)
safe_extract(my_list, "c", 1)

ggpicrust2 documentation built on April 13, 2025, 9:08 a.m.