str.replace.by.blocks: Replaces in str every occurence of pattern by replacement

View source: R/stringtools.R

str.replace.by.blocksR Documentation

Replaces in str every occurence of pattern by replacement

Description

Replaces in str every occurence of pattern by replacement

Usage

## S3 method for class 'replace.by.blocks'
str(str, pattern, replacement, blocks = NULL,
  sub.txt = "SUB", block.start, block.end, block.ignore = NULL,
  use.levels = NULL, fixed = TRUE, only.replace.smaller.than = NULL,
  only.replace.larger.than = NULL)

Arguments

str

the string to replaced

pattern

the substring to be replaced

replacment

the new substrings

block

a block retrieved from str.block.pos alternatively, you can provide block.start and block.end

block.start

string with which the blocks start, e.g. "("

block.end

string with which the blocks end, e.g. ")"

only.replace.smaller.than

if not NULL only replaces matches whose number of characters is less or equal to only.replace.smaller.than

only.replace.larger.than

if not NULL only replaces matches whose number of characters is bigger or equal to only.replace.larger.than

Value

a string

Examples

## Not run: 
  # Replace latex fractions
  str = "5+\frac{x^2+x^2}{1+\frac{2}{x*5}}*2"
  str.replace.by.blocks(str,"\frac{_SUB_}{_SUB_}","(_SUB1_)/(_SUB2_)",
                        block.start = "{", block.end = "}")  
  str.replace.by.blocks(str,"\frac{_SUB_}{_SUB_}","(_SUB1_)/(_SUB2_)",
                        block.start = "{", block.end = "}",
                        only.replace.larger.than=20)  
  str.replace.by.blocks(str,"\frac{_SUB_}{_SUB_}","(_SUB1_)/(_SUB2_)",
                        block.start = "{", block.end = "}",
                        only.replace.smaller.than=20)  
  str ="-\frac{\sigma_{m}-\beta\sigma_{b}}{\beta-1}=\frac{\sigma_{m}-\beta\sigma_{b}}{1-\beta}"
  
  str ="\frac{1}{2}=\frac{3}{4}"
  str.replace.by.blocks(str,"\frac{_SUB_}{_SUB_}","(_SUB1_)/(_SUB2_)",
                        block.start = "{", block.end = "}")  
  

## End(Not run)

skranz/stringtools documentation built on May 11, 2022, 4:48 a.m.