replace_hash: Replace Hashes

Description Usage Arguments Value Examples

View source: R/replace_hash.R

Description

Replaces Twitter style hash tags (e.g., '#rstats').

Usage

1
replace_hash(x, pattern = qdapRegex::grab("rm_hash"), replacement = "", ...)

Arguments

x

The text variable.

pattern

Character time regex string to be matched in the given character vector.

replacement

A function to operate on the extracted matches or a character string which is a replacement for the matched pattern.

...

ignored.

Value

Returns a vector with hashes replaced.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
x <- c("@hadley I like #rstats for #ggplot2 work.",
    "Difference between #magrittr and #pipeR, both implement pipeline operators for #rstats: 
        http://renkun.me/r/2014/07/26/difference-between-magrittr-and-pipeR.html @timelyportfolio",
    "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization 
        presentation #user2014. http://ramnathv.github.io/user2014-rcharts/#1"
)

replace_hash(x)
replace_hash(x, replacement = '<<HASH>>')
replace_hash(x, replacement = '$3')

## Replacement with a function
replace_hash(x, 
    replacement = function(x){
        paste0('{{', gsub('^#', 'TOPIC: ', x), '}}')
    }
)

Example output

[1] "@hadley I like  for  work."                                                                                                                                           
[2] "Difference between  and , both implement pipeline operators for : \n        http://renkun.me/r/2014/07/26/difference-between-magrittr-and-pipeR.html @timelyportfolio"
[3] "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization \n        presentation . http://ramnathv.github.io/user2014-rcharts/#1"    
[1] "@hadley I like <<HASH>> for <<HASH>> work."                                                                                                                                                   
[2] "Difference between <<HASH>> and <<HASH>>, both implement pipeline operators for <<HASH>>: \n        http://renkun.me/r/2014/07/26/difference-between-magrittr-and-pipeR.html @timelyportfolio"
[3] "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization \n        presentation <<HASH>>. http://ramnathv.github.io/user2014-rcharts/#1"                    
[1] "@hadley I like rstats for ggplot2 work."                                                                                                                                                 
[2] "Difference between magrittr and pipeR, both implement pipeline operators for rstats: \n        http://renkun.me/r/2014/07/26/difference-between-magrittr-and-pipeR.html @timelyportfolio"
[3] "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization \n        presentation user2014. http://ramnathv.github.io/user2014-rcharts/#1"               
[1] "@hadley I like {{TOPIC: rstats}} for {{TOPIC: ggplot2}} work."                                                                                                                                                              
[2] "Difference between {{TOPIC: magrittr}} and {{TOPIC: pipeR}}, both implement pipeline operators for {{TOPIC: user2014}}: \n        http://renkun.me/r/2014/07/26/difference-between-magrittr-and-pipeR.html @timelyportfolio"
[3] "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization \n        presentation {{TOPIC: rstats}}. http://ramnathv.github.io/user2014-rcharts/#1"                                         
Warning message:
In data.table::data.table(hit_id = rep(seq_len(length(h)), h), pat = reps,  :
  Item 2 is of size 5 but maximum size is 6 (recycled leaving remainder of 1 items)

textclean documentation built on May 2, 2019, 7:22 a.m.