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: 210 × 18
#>       id slug     type  config created_at updated_at last_edited_at published_at
#>    <int> <chr>    <chr> <chr>  <chr>      <chr>      <chr>          <chr>       
#>  1  7953 hdi-vs-… Line… "{\"i… 2024-07-2… 2024-07-2… 2024-07-28 13… "2024-07-26…
#>  2  7947 low-car… Scat… "{\"i… 2024-07-2… 2024-07-2… 2024-07-22 10… "2024-07-22…
#>  3  7943 tempera… Scat… "{\"i… 2024-07-1… 2024-07-1… 2024-07-19 08… ""          
#>  4  7926 global-… Stac… "{\"i… 2024-07-0… 2024-07-1… 2024-07-19 09… "2024-07-03…
#>  5  7925 spring-… Stac… "{\"i… 2024-07-0… 2024-07-0… 2024-07-05 08… "2024-07-03…
#>  6  7924 autumn-… Stac… "{\"i… 2024-07-0… 2024-07-0… 2024-07-05 08… "2024-07-03…
#>  7  7923 winter-… Stac… "{\"i… 2024-07-0… 2024-07-0… 2024-07-05 08… "2024-07-03…
#>  8  7922 summer-… Stac… "{\"i… 2024-07-0… 2024-07-0… 2024-07-05 08… "2024-07-03…
#>  9  7921 country… Stac… "{\"i… 2024-07-0… 2024-07-1… 2024-07-10 10… "2024-07-03…
#> 10  7917 materia… Stac… "{\"i… 2024-07-0… 2024-07-2… 2024-07-24 11… "2024-07-14…
#> # ℹ 200 more rows
#> # ℹ 10 more variables: last_edited_by_user_id <int>,
#> #   last_edited_by_user_id_label <chr>, published_by_user_id <int>,
#> #   published_by_user_id_label <chr>, is_indexable <int>, title <chr>,
#> #   subtitle <chr>, note <chr>, title_plus_variant <chr>,
#> #   config_with_defaults <chr>

# Search only in the title column
owid_search(catalog, c("climate", "carbon"), c("title"))
#> # A tibble: 48 × 18
#>       id slug     type  config created_at updated_at last_edited_at published_at
#>    <int> <chr>    <chr> <chr>  <chr>      <chr>      <chr>          <chr>       
#>  1  7947 low-car… Scat… "{\"i… 2024-07-2… 2024-07-2… 2024-07-22 10… 2024-07-22 …
#>  2  7917 materia… Stac… "{\"i… 2024-07-0… 2024-07-2… 2024-07-24 11… 2024-07-14 …
#>  3  7910 co2-hea… Line… "{\"i… 2024-06-2… 2024-07-1… 2024-07-12 12… 2024-06-25 …
#>  4  7791 warm-se… Stac… "{\"i… 2024-05-0… 2024-06-2… 2024-06-28 06… 2024-06-28 …
#>  5  7634 willing… Scat… "{\"i… 2024-02-1… 2024-04-0… 2024-03-06 12… 2024-02-20 …
#>  6  7633 support… Line… "{\"i… 2024-02-1… 2024-04-1… 2024-04-16 11… 2024-02-20 …
#>  7  7632 share-b… Line… "{\"i… 2024-02-1… 2024-04-0… 2024-03-29 16… 2024-02-20 …
#>  8  7631 support… Line… "{\"i… 2024-02-1… 2024-04-0… 2024-02-20 12… 2024-02-18 …
#>  9  7630 support… Line… "{\"i… 2024-02-1… 2024-04-0… 2024-03-07 12… 2024-02-18 …
#> 10  7623 weather… Line… "{\"i… 2024-02-1… 2024-04-0… 2024-02-16 16… 2024-02-13 …
#> # ℹ 38 more rows
#> # ℹ 10 more variables: last_edited_by_user_id <int>,
#> #   last_edited_by_user_id_label <chr>, published_by_user_id <int>,
#> #   published_by_user_id_label <chr>, is_indexable <int>, title <chr>,
#> #   subtitle <chr>, note <chr>, title_plus_variant <chr>,
#> #   config_with_defaults <chr>
# }