Skip to content

Commit

Permalink
Merge pull request #88 from MichaelChirico/patch-3
Browse files Browse the repository at this point in the history
Code style pass on stackoverflow vignette
  • Loading branch information
kevinushey authored Sep 13, 2023
2 parents bc3b183 + 541a868 commit 8a98617
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions vignettes/stackoverflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ groups
#' fewer members will have their members recycled rather than `NA`, so instead
#' explicitly fill with `NA`.

largest_group <- max(sapply(groups, length))
largest_group <- max(lengths(groups))
largest_group

groups <- lapply(groups, function(group) {
Expand Down Expand Up @@ -90,7 +90,7 @@ matches
#' ### [http://stackoverflow.com/questions/22976472][]
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.

txt <- as.character("this is just a test! i'm not sure if this is O.K. or if it will work? who knows. regex is sorta new to me.. There are certain cases that I may not figure out?? sad! ^_^")
txt <- "this is just a test! i'm not sure if this is O.K. or if it will work? who knows. regex is sorta new to me.. There are certain cases that I may not figure out?? sad! ^_^"

re <- rex(
capture(name = "first_letter", alnum),
Expand Down Expand Up @@ -161,14 +161,14 @@ re_matches(x$address, re)
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.

library(rex)
x <- c(
x <-
"https://support.google.com/blogger/topic/12457
https://support.google.com/blogger/topic/12457.
https://support.google.com/blogger/topic/12457]
<<https://support.google.com/blogger/topic/12457>>
https://support.google.com/blogger/topic/12457,
https://support.google.com/blogger/topic/12457),
xxxxxxhttps://support.google.com/blogger/topic/12457),hhhththta")
xxxxxxhttps://support.google.com/blogger/topic/12457),hhhththta"

re <- rex(
capture(name = "url",
Expand All @@ -180,7 +180,7 @@ re_matches(x, re, global = TRUE)[[1]]

#' ### [http://stackoverflow.com/questions/27219421][]
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.
tmp <- c("Little Street","A323", "Essex Road (A43)", "M43","Orange street","M4","B2045","New Street")
tmp <- c("Little Street","A323", "Essex Road (A43)", "M43", "Orange street", "M4", "B2045", "New Street")

library(rex)
classify_road <- function(x) {
Expand Down Expand Up @@ -215,15 +215,15 @@ regexpr(re, x, perl = TRUE)
#' ### [http://stackoverflow.com/questions/23447261][]
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.

x = structure(list(text = structure(c(4L, 6L, 1L, 2L, 5L, 3L), .Label = c("ãããæããããéãããæãããInappropriate announce:-(",
"@AirAsia your direct debit (Maybank) payment gateways is not working. Is it something you are working to fix?",
"@AirAsia Apart from the slight delay and shortage of food on our way back from Phuket, both flights were very smooth. Kudos :)",
"RT @AirAsia: ØØÙØÙÙÙÙ ÙØØØ ØØØÙ ÙØØØØÙ ØØØØÙÙÙí í Now you can enjoy a #great :D breakfast onboard with our new breakfast meals! :D",
"xdek ke flight @AirAsia Malaysia to LA... hahah..:p bagi la promo murah2 sikit, kompom aku beli...",
x <- structure(list(text = structure(c(4L, 6L, 1L, 2L, 5L, 3L), .Label = c("ãããæããããéãããæãããInappropriate announce:-(",
"@AirAsia your direct debit (Maybank) payment gateways is not working. Is it something you are working to fix?",
"@AirAsia Apart from the slight delay and shortage of food on our way back from Phuket, both flights were very smooth. Kudos :)",
"RT @AirAsia: ØØÙØÙÙÙÙ ÙØØØ ØØØÙ ÙØØØØÙ ØØØØÙÙÙí í Now you can enjoy a #great :D breakfast onboard with our new breakfast meals! :D",
"xdek ke flight @AirAsia Malaysia to LA... hahah..:p bagi la promo murah2 sikit, kompom aku beli...",
"You know there is a problem when customer service asks you to wait for 103 minutes and your no is 42 in the queue. X-("
), class = "factor"), created = structure(c(5L, 4L, 4L, 3L, 2L,
1L), .Label = c("1/2/2014 16:14", "1/2/2014 17:00", "3/2/2014 0:54",
"3/2/2014 0:58", "3/2/2014 1:28"), class = "factor")), .Names = c("text",
), class = "factor"), created = structure(c(5L, 4L, 4L, 3L, 2L,
1L), .Label = c("1/2/2014 16:14", "1/2/2014 17:00", "3/2/2014 0:54",
"3/2/2014 0:58", "3/2/2014 1:28"), class = "factor")), .Names = c("text",
"created"), class = "data.frame", row.names = c(NA, -6L))

emots <- as.character(outer(c(":", ";", ":-", ";-"), c(")", "(", "]", "[", "D", "o", "O", "P", "p"), paste0))
Expand All @@ -234,7 +234,7 @@ re_matches(x$text,
or(emots)
)
),
global = T)
global = TRUE)

#' ### [http://stackoverflow.com/questions/27234040][]
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.
Expand Down Expand Up @@ -297,7 +297,7 @@ substring(x, locs$start - 6, locs$end + 6)

#' ### [http://stackoverflow.com/questions/15954171][]
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.
x <- c("System configuration: lcpu=96 mem=196608MB ent=16.00")
x <- "System configuration: lcpu=96 mem=196608MB ent=16.00"

library(rex)
val <- as.numeric(
Expand Down Expand Up @@ -336,7 +336,7 @@ re_matches(x,

#' ### [http://stackoverflow.com/questions/27238323][]
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.
string = c("ABC3JFD456", "ARST4DS324")
string <- c("ABC3JFD456", "ARST4DS324")

re_matches(string,
rex(
Expand Down Expand Up @@ -375,7 +375,7 @@ minimal <- html("<!doctype html><title>blah</title> <p>&nbsp;foo")

bodytext <- minimal %>%
html_node("body") %>%
html_text
html_text()

re_substitutes(bodytext, rex(spaces), "", global = TRUE)

Expand Down Expand Up @@ -466,7 +466,7 @@ re_matches(x, re)
#' ### <http://stackoverflow.com/questions/27422350/extract-character-preceding-first-dot-in-a-string>
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.

my.data <- read.table(text = '
my.data <- read.table(text = "
my.string state
......... A
1........ B
Expand All @@ -475,25 +475,25 @@ my.data <- read.table(text = '
1111113.. E
111111111 F
111111111 G
', header = TRUE, stringsAsFactors = FALSE)
", header = TRUE, stringsAsFactors = FALSE)

library(rex)

re_matches(my.data$my.string,
rex(capture(except(".")), "."))$'1'
rex(capture(except(".")), "."))$"1"

#' ### <http://stackoverflow.com/questions/27410736>
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.
string <- "Shakira - Wolf - 02.Hips don't lie.mp3"

library(rex)
re_matches(string,
rex(capture(zero_or_more(any, type='lazy')), spaces, "-"))$'1'
rex(capture(zero_or_more(any, type="lazy")), spaces, "-"))$"1"

#' ### <http://stackoverflow.com/questions/27400286/>
#' Using [rex](http://cran.r-project.org/web/packages/rex/index.html) may make this type of task a little simpler.

string <- "I t is tim e to g o"
string <- "I t is tim e to g o"
library(rex)
re_substitutes(string, rex(
space %if_next_is%
Expand Down

0 comments on commit 8a98617

Please sign in to comment.