Просмотр исходного кода

Move stringr to Suggests

Replaced a few calls to stringr with stringi (which has to stay for unicode encoding function). Not likely that people won't have stringr, but makes the dependencies a little better.
pull/21/head
Garrick Aden-Buie 7 лет назад
Родитель
Сommit
9782606b1e
3 измененных файлов: 37 добавлений и 17 удалений
  1. +3
    -3
      DESCRIPTION
  2. +32
    -12
      R/gadget_server.R
  3. +2
    -2
      R/regex.R

+ 3
- 3
DESCRIPTION Просмотреть файл

@@ -42,12 +42,12 @@ Imports:
rstudioapi,
shiny (>= 0.13),
stringi,
stringr,
tidyr,
utils
Suggests:
testthat,
rematch2
rematch2,
stringr,
testthat
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)

+ 32
- 12
R/gadget_server.R Просмотреть файл

@@ -216,7 +216,7 @@ regexplain_gadget_server <- function(update_available = NULL) {
req(replacement())
regexFn(
rtext(),
stringr::regex(
stringr_regex(
pattern(),
ignore_case = 'ignore.case' %in% input$regex_options,
literal = 'fixed' %in% input$regex_options
@@ -226,7 +226,7 @@ regexplain_gadget_server <- function(update_available = NULL) {
} else {
regexFn(
rtext(),
stringr::regex(
stringr_regex(
pattern(),
ignore_case = 'ignore.case' %in% input$regex_options,
literal = 'fixed' %in% input$regex_options
@@ -245,6 +245,14 @@ regexplain_gadget_server <- function(update_available = NULL) {
print(x)
})

stringr_regex <- function(pattern, ignore_case = FALSE, literal = FALSE) {
if (!requireNamespace("stringr", quietly = TRUE)) return(NULL)
do.call(
eval(parse(text = "stringr::regex")),
list(pattern = pattern, ignore_case, ignore_case, literal = literal)
)
}

# ---- Server - Tab - Help ----
HELP_DEFAULT_TEXT <- c(
"<h3>Welcome to RegExplain</h3>",
@@ -413,10 +421,14 @@ regexplain_gadget_server <- function(update_available = NULL) {

observeEvent(input$help_try_this_hs_colors_text, {
color_match <- "\\b(red|orange|yellow|green|blue|purple)\\b|red"
color_text <- stringr::sentences[grepl(color_match, stringr::sentences)]
color_text <- sample(color_text, 25)
updateTextAreaInput(session, "text", value = paste(color_text, collapse = "\n"))
showNotification("Text loaded! View it in Text tab", type = 'message')
if (requireNamespace("stringr", quietly = TRUE)) {
color_text <- stringr::sentences[grepl(color_match, stringr::sentences)]
color_text <- sample(color_text, 25)
updateTextAreaInput(session, "text", value = paste(color_text, collapse = "\n"))
showNotification("Text loaded! View it in Text tab", type = 'message')
} else {
showNotification("Please install {stringr} for this example", type = 'error')
}
})

observeEvent(input$help_try_this_hs_colors_pattern, {
@@ -450,9 +462,13 @@ regexplain_gadget_server <- function(update_available = NULL) {
})

observeEvent(input$help_try_this_hs_words_text, {
hs_text <- sample(stringr::sentences, 25)
updateTextAreaInput(session, "text", value = paste(hs_text, collapse = "\n"))
showNotification("Text loaded! View it in Text tab", type = 'message')
if (requireNamespace("stringr", quietly = TRUE)) {
hs_text <- sample(stringr::sentences, 25)
updateTextAreaInput(session, "text", value = paste(hs_text, collapse = "\n"))
showNotification("Text loaded! View it in Text tab", type = 'message')
} else {
showNotification("Please install {stringr} for this example", type = 'error')
}
})

observeEvent(input$help_try_this_hs_words_pattern, {
@@ -474,9 +490,13 @@ regexplain_gadget_server <- function(update_available = NULL) {
})

observeEvent(input$help_try_this_hs_refs_text, {
hs_text <- sample(stringr::sentences, 25)
updateTextAreaInput(session, "text", value = paste(hs_text, collapse = "\n"))
showNotification("Text loaded! View it in Text tab", type = 'message')
if (requireNamespace("stringr", quietly = TRUE)) {
hs_text <- sample(stringr::sentences, 25)
updateTextAreaInput(session, "text", value = paste(hs_text, collapse = "\n"))
showNotification("Text loaded! View it in Text tab", type = 'message')
} else {
showNotification("Please install {stringr} for this example", type = 'error')
}
})

observeEvent(input$help_try_this_hs_refs_pattern, {

+ 2
- 2
R/regex.R Просмотреть файл

@@ -246,8 +246,8 @@ view_regex <- function(
res <- purrr::map_chr(res, function(resi) {
result_pad <- ""
if (grepl("pad\\d{2}", resi)) {
max_pad <- max(stringr::str_extract_all(resi, "pad\\d{2}")[[1]])
max_pad_level <- as.integer(stringr::str_extract(max_pad, "\\d{2}"))
max_pad <- max(stringi::stri_extract_all_regex(resi, "pad\\d{2}")[[1]])
max_pad_level <- as.integer(stringi::stri_extract_all_regex(max_pad, "\\d{2}"))
if (max_pad_level - 3 > 0) {
result_pad <- sprintf("pad%02d", max_pad_level - 3)
}

Загрузка…
Отмена
Сохранить