replace_url: Replace URLs

Description Usage Arguments Value Examples

View source: R/replace_url.R

Description

Replaces URLs.

Usage

1
replace_url(x, pattern = qdapRegex::grab("rm_url"), 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 URLs replaced.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
x <- c("@hadley I like #rstats for #ggplot2 work. ftp://cran.r-project.org/incoming/",
    "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. https://ramnathv.github.io/user2014-rcharts/#1",
    NA 
)

replace_url(x)
replace_url(x, replacement = '<<URL>>')

## Not run: 
## Replacement with a function
library(urltools)
replace_url(x, 
    replacement = function(x){
        sprintf('{{%s}}', urltools::url_parse(x)$domain)
    }
)

## End(Not run)

Example output

[1] "@hadley I like #rstats for #ggplot2 work. "                                                                                   
[2] "Difference between #magrittr and #pipeR, both implement pipeline operators for #rstats: \n         @timelyportfolio"          
[3] "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization \n        presentation #user2014. "
[4] NA                                                                                                                             
[1] "@hadley I like #rstats for #ggplot2 work. <<URL>>"                                                                                   
[2] "Difference between #magrittr and #pipeR, both implement pipeline operators for #rstats: \n        <<URL>> @timelyportfolio"          
[3] "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization \n        presentation #user2014. <<URL>>"
[4] NA                                                                                                                                    
[1] "@hadley I like #rstats for #ggplot2 work. {{cran.r-project.org}}"                                                                                   
[2] "Difference between #magrittr and #pipeR, both implement pipeline operators for #rstats: \n        {{renkun.me}} @timelyportfolio"                   
[3] "Slides from great talk: @ramnath_vaidya: Interactive slides from Interactive Visualization \n        presentation #user2014. {{ramnathv.github.io}}"
[4] NA                                                                                                                                                   

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