Skip to contents

Filters a literature matrix based on a specified condition, with the option to restrict the search to a specific column. The function supports both column names and numeric indices for column selection.

Usage

search_record(.data, column = NULL, where = NULL)

Arguments

.data

A data frame to search within.

column

Optional. The column to search in, specified either by name or numeric index. If NULL (default), the search is performed across all columns.

where

A logical expression that defines the search condition. Must evaluate to a logical vector of the same length as the number of rows in `.data`.

Value

A filtered data frame containing only the rows that match the search condition. If a specific column was selected, only that column is returned.

Examples

df <- data.frame(
  id = 1:5,
  name = c("John", "Jane", "Bob", "Alice", "John"),
  age = c(25, 30, 35, 28, 40)
)

# Search across all columns where age > 30
search_record(df, where = age > 30)
#>   id name age
#> 3  3  Bob  35
#> 5  5 John  40

# Search only in the name column for "John"
search_record(df, column = "name", where = name == "John")
#>   name
#> 1 John
#> 5 John

# Search using column index
search_record(df, column = 2, where = name == "Jane")
#>   name
#> 2 Jane