Split character vector, i.e. each element, by a seperator and convert the resulting exploded string into a typed list / data frame of meta information.

str_parse(
  x,
  ext = NULL,
  which = NULL,
  types,
  names,
  as.df = TRUE,
  append = TRUE,
  ...
)

Arguments

x

[character]
Input strings.

ext

[character(1) | NULL]
Optional file extension which should be dropped prior to splitting.

which

[integer]
Integer vector of relevant positions, i.e. positions in the exploded string which are of interest. Defaults to all positions.

types

[character(1)]
Single character where the letter at position i characterizes the type of the corresponding element in the exploded string. Possible letters are “c” (character), “n” (numeric), “i” (integer) or “l” (logical).

names

[character]
Vector of names for the extracted components.

as.df

[logical(1)]
Should the result be a data frame? Default is TRUE. If FALSE a list of named lists is returned.

append

[logical(1)]
Should the values of x be dropped or appended to the ouptut via component “input”? Default is TRUE.

...

[any]
Further arguments passed down to strsplit. Here, argument split is the most interesting one.

Value

A data frame or a list (depends on as.df).

See also

Other string helpers: str_explode(), str_to_shortcut()

Examples

x = c("char_int10_num10.4", "char_int28_num30.444") str_parse(x, types = "cin", names = c("character", "integer", "numeric"), split = "_")
#> character integer numeric input #> 1 char 10 10.400 char_int10_num10.4 #> 2 char 28 30.444 char_int28_num30.444
str_parse(x, which = 2:3, types = "in", names = c("integer", "numeric"), split = "_")
#> integer numeric input #> 1 10 10.400 char_int10_num10.4 #> 2 28 30.444 char_int28_num30.444
str_parse(x, which = 2:3, types = "in", names = c("integer", "numeric"), as.df = FALSE, append = FALSE, split = "_")
#> [[1]] #> [[1]]$integer #> [1] 10 #> #> [[1]]$numeric #> [1] 10.4 #> #> #> [[2]] #> [[2]]$integer #> [1] 28 #> #> [[2]]$numeric #> [1] 30.444 #> #>