Skip to contents

This function searches for a vector of keywords within specified columns of an OWID catalog data frame. If no columns are specified, it searches all character and factor columns.

Usage

owid_search(data, keywords, columns = NULL)

Arguments

data

A data frame, typically obtained from owid_get_catalog.

keywords

A character vector of one or more keywords to search for. The search is case-insensitive.

columns

An optional character vector of column names to search within. If NULL (default), all character and factor columns are searched.

Value

A filtered data frame containing only rows that match at least one of the keywords in at least one of the specified columns.

Examples

# \donttest{
# Get the OWID catalog
catalog <- owid_get_catalog()

# Search for climate or carbon in all text columns
owid_search(catalog, c("climate", "carbon"))
#> # A tibble: 206 × 19
#>    rowid    id config_id            is_inheritance_enabled created_at updated_at
#>    <int> <int> <chr>                <lgl>                  <date>     <date>    
#>  1  5166  8555 0195a9ea-1bb2-7af4-… FALSE                  2025-03-18 2025-03-18
#>  2  5131  8509 01950523-a967-7c01-… TRUE                   2025-02-14 2025-03-23
#>  3  5130  8508 01950523-a857-72c1-… TRUE                   2025-02-14 2025-03-23
#>  4  5105  8472 0194b2a8-e036-7c09-… FALSE                  2025-01-29 2025-04-07
#>  5  4900  8266 01933e25-e0bc-70e5-… FALSE                  2024-11-18 2024-11-22
#>  6  4869  8222 0192d85f-7e6f-7cbb-… FALSE                  2024-10-29 2025-04-07
#>  7  5059  8032 0191c217-8b0d-7612-… TRUE                   2024-09-05 2025-05-26
#>  8  5058  8031 0191c217-8a17-7cd8-… TRUE                   2024-09-05 2025-05-26
#>  9  5057  8030 0191c217-8916-71c6-… TRUE                   2024-09-05 2025-05-26
#> 10  5056  8029 0191c217-8831-7fc9-… TRUE                   2024-09-05 2025-05-26
#> # ℹ 196 more rows
#> # ℹ 13 more variables: last_edited_at <date>, published_at <date>,
#> #   last_edited_by_user_id <int>, published_by_user_id <int>,
#> #   is_indexable <lgl>, config <chr>, slug <chr>, type <chr>, title <chr>,
#> #   subtitle <chr>, note <chr>, title_plus_variant <chr>, is_published <lgl>

# Search only in the title column
owid_search(catalog, c("climate", "carbon"), c("title"))
#> # A tibble: 47 × 19
#>    rowid    id config_id            is_inheritance_enabled created_at updated_at
#>    <int> <int> <chr>                <lgl>                  <date>     <date>    
#>  1  4678  7917 0191b6c7-5a09-78a9-… FALSE                  2024-07-01 2024-11-14
#>  2  4672  7910 0191b6c7-59fe-7cb2-… FALSE                  2024-06-21 2024-10-02
#>  3  4591  7791 0191b6c7-5969-7055-… FALSE                  2024-05-07 2024-10-30
#>  4  4488  7634 0191b6c7-58a1-7fee-… FALSE                  2024-02-18 2024-11-15
#>  5  4487  7633 0191b6c7-589f-7ed3-… FALSE                  2024-02-18 2024-09-05
#>  6  4486  7632 0191b6c7-589e-7ac5-… FALSE                  2024-02-18 2024-09-05
#>  7  4485  7631 0191b6c7-589c-7aee-… FALSE                  2024-02-18 2024-09-05
#>  8  4484  7630 0191b6c7-589a-71e3-… FALSE                  2024-02-18 2024-09-05
#>  9  4477  7623 0191b6c7-588e-723c-… FALSE                  2024-02-13 2024-09-05
#> 10  4453  7579 0191b6c7-5856-74e7-… FALSE                  2024-02-06 2025-05-22
#> # ℹ 37 more rows
#> # ℹ 13 more variables: last_edited_at <date>, published_at <date>,
#> #   last_edited_by_user_id <int>, published_by_user_id <int>,
#> #   is_indexable <lgl>, config <chr>, slug <chr>, type <chr>, title <chr>,
#> #   subtitle <chr>, note <chr>, title_plus_variant <chr>, is_published <lgl>
# }