Description Usage Arguments Value Examples
View source: R/replace_email.R
Replaces email addresses.
1 2 | replace_email(x, pattern = qdapRegex::grab("rm_email"), replacement = "",
...)
|
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. |
Returns a vector with email addresses replaced.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | x <- c(
"fred is fred@foo.com and joe is joe@example.com - but @this is a",
"twitter handle for twit@here.com or foo+bar@google.com/fred@foo.fnord",
"hello world",
NA
)
replace_email(x)
replace_email(x, replacement = '<<EMAIL>>')
replace_email(x, replacement = '<a href="mailto:$1" target="_blank">$1</a>')
## Replacement with a function
replace_email(x,
replacement = function(x){
sprintf('<a href="mailto:%s" target="_blank">%s</a>', x, x)
}
)
replace_email(x,
replacement = function(x){
gsub('@.+$', ' {{at domain}}', x)
}
)
|
[1] "fred is and joe is - but @this is a"
[2] "twitter handle for or /"
[3] "hello world"
[4] NA
[1] "fred is <<EMAIL>> and joe is <<EMAIL>> - but @this is a"
[2] "twitter handle for <<EMAIL>> or <<EMAIL>>/<<EMAIL>>"
[3] "hello world"
[4] NA
[1] "fred is <a href=\"mailto:fred@foo.com\" target=\"_blank\">fred@foo.com</a> and joe is <a href=\"mailto:joe@example.com\" target=\"_blank\">joe@example.com</a> - but @this is a"
[2] "twitter handle for <a href=\"mailto:twit@here.com\" target=\"_blank\">twit@here.com</a> or <a href=\"mailto:foo+bar@google.com\" target=\"_blank\">foo+bar@google.com</a>/<a href=\"mailto:fred@foo.fnord\" target=\"_blank\">fred@foo.fnord</a>"
[3] "hello world"
[4] NA
[1] "fred is <a href=\"mailto:fred@foo.com\" target=\"_blank\">fred@foo.com</a> and joe is <a href=\"mailto:joe@example.com\" target=\"_blank\">joe@example.com</a> - but @this is a"
[2] "twitter handle for <a href=\"mailto:twit@here.com\" target=\"_blank\">twit@here.com</a> or <a href=\"mailto:foo+bar@google.com\" target=\"_blank\">foo+bar@google.com</a>/<a href=\"mailto:fred@foo.fnord\" target=\"_blank\">fred@foo.fnord</a>"
[3] "hello world"
[4] NA
[1] "fred is fred {{at domain}} and joe is joe {{at domain}} - but @this is a"
[2] "twitter handle for twit {{at domain}} or foo+bar {{at domain}}/fred {{at domain}}"
[3] "hello world"
[4] NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.