Learn R Programming

unglue (version 0.1.0)

unglue_sub: unglue_sub

Description

substitute substrings using strings or replacement functions

Usage

unglue_sub(x, patterns, repl, open = "{", close = "}")

Arguments

x

character vector

patterns

a character vector or a list of character vectors, if a list, items will be pasted using an empty separator ("").

repl

function to apply on matched substrings, formula (if package rlang is installed), substring, or named list of such.

open

The opening delimiter.

close

The closing delimiter.

Examples

Run this code
# NOT RUN {
unglue_sub(
  c("a and b", "foo or bar"),
  c("{x} and {y}", "{x} or {z}"),
  "XXX")

unglue_sub(
  c("a and b", "foo or bar"),
  c("{x} and {y}", "{x} or {z}"),
  toupper)

unglue_sub(
  c("a and b", "foo or BAR"),
  c("{x} and {y}", "{x} or {z}"),
  list(x= "XXX", y = toupper, z = tolower))

# }

Run the code above in your browser using DataLab