str_parse: Parse strings

View source: R/str_parse.R

str_parseR Documentation

Parse strings

Description

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.

Usage

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_to_shortcut()

Examples

x = c("char_int10_num10.4", "char_int28_num30.444")
str_parse(x, types = "cin", names = c("character", "integer", "numeric"), split = "_")
str_parse(x, which = 2:3, types = "in", names = c("integer", "numeric"), split = "_")
str_parse(x, which = 2:3, types = "in", names = c("integer", "numeric"),
  as.df = FALSE, append = FALSE, split = "_")

jakobbossek/re documentation built on Nov. 15, 2024, 1:42 a.m.