Learn R Programming

NMsim (version 0.1.6)

overwrite: Create function that modifies text elements in a vector

Description

Create function that modifies text elements in a vector

Usage

overwrite(..., fixed = TRUE)

Value

A function that runs `gsub` to character vectors

Arguments

...

Passed to `gsub()`

fixed

This is passed to gsub(), but `overwrite()`'s default behavior is the opposite of the one of `gsub()`. Default is `FALSE` which means that strings that are exactly matched will be replaced. This is useful because strings like `THETA(1)` contains special characters. Use `fixed=FALSE` to use regular expressions. Also, see other arguments accepted by `gsub()` for advanced features.

Examples

Run this code
myfun <- overwrite("b","d")
myfun(c("a","b","c","abc"))
## regular expressions
myfun2 <- overwrite("b.*","d",fixed=FALSE)
myfun2(c("a","b","c","abc"))

Run the code above in your browser using DataLab