[Experimental]

tidy_keyword() tidy keyword values for database search.

tidy_keyword(
  ...,
  min_chars = 1,
  delimiter = ",",
  enclosure = "double quote",
  clean_modifiers = TRUE,
  sort = FALSE,
  na_rm = TRUE,
  duplicate_rm = TRUE
)

Arguments

...

One or more character objects containing keywords.

min_chars

(optional) A number indicating the minimal number of characters a keyword must have. Keywords that don't comply to this setting will be transformed to NA (default: 1).

delimiter

(optional) A string with the delimiter used on ... values. Use delimiter = NULL to disable this behavior (default: NULL).

enclosure

(optional) A string indicating the type of enclosure for keywords with special characters (like spaces) (default: "double quote").

clean_modifiers

(optional) A logical value indicating if keywords with modifiers must be transformed to NA (default: TRUE).

sort

(optional) A logical value indicating if the output must be ordered alphabetically (default: FALSE).

na_rm

(optional) A logical value indicating if NA values must be removed from the output (default: TRUE).

duplicate_rm

(optional) A logical value indicating if duplicate values must be removed from the output (default: TRUE).

Value

A character object with keywords in ... tidied.

Details

enclosure argument

The enclosure argument let you choose the type of enclosure for keywords with special characters, i.e, all keywords that don't conform to the pattern "^[a-zA-Z0-9]+$". The default value is "double quote".

Valid choices for this argument are:

  • "single quote": to enclose the keyword with single quotes (e.g., 'lorem')

  • "double quote": to enclose the keyword with double quotes (e.g., "ipsum")

  • "round bracket": to enclose the keyword with round brackets or parenthesis (e.g. (dolor))

  • "curly bracket": to enclose the keyword with curly brackets (e.g. {dolor})

  • "square bracket": to enclose the keyword with square brackets (e.g. [dolor])

clean modifiers argument

Modifiers follow the [*$?():'\"] pattern. If clean modifiers is set to TRUE, all keywords with the latter pattern will be transformed to NA.

See also

Other keyword functions: query()

Examples

tidy_keyword("Lorem", "Ipsum dolor", c("sit", "amet"))
#> [1] "lorem"           "\"ipsum dolor\"" "sit"             "amet"           
#> [1] "lorem"           "\"ipsum dolor\"" "sit" # Expected
#> [4] "amet" # Expected

tidy_keyword("Lorem", "Ipsum dolor", c("sit", "amet"), sort = TRUE)
#> [1] "amet"            "\"ipsum dolor\"" "lorem"           "sit"            
#> [1] "amet"            "\"ipsum dolor\"" "lorem" # Expected
#> [4] "sit" # Expected

tidy_keyword("Lorem", "Ipsum, dolor", delimiter = ",")
#> [1] "lorem" "ipsum" "dolor"
#> [1] "lorem" "ipsum" "dolor" # Expected

tidy_keyword("Lorem", "Ipsum*", clean_modifiers = TRUE, na_rm = TRUE)
#> [1] "lorem"
#> [1] "lorem" # Expected

tidy_keyword("Lorem", "Ipsum*", clean_modifiers = TRUE, na_rm = FALSE)
#> [1] "lorem" NA     
#> [1] "lorem" NA # Expected