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

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 Просмотреть файл

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

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

req(replacement()) req(replacement())
regexFn( regexFn(
rtext(), rtext(),
stringr::regex(
stringr_regex(
pattern(), pattern(),
ignore_case = 'ignore.case' %in% input$regex_options, ignore_case = 'ignore.case' %in% input$regex_options,
literal = 'fixed' %in% input$regex_options literal = 'fixed' %in% input$regex_options
} else { } else {
regexFn( regexFn(
rtext(), rtext(),
stringr::regex(
stringr_regex(
pattern(), pattern(),
ignore_case = 'ignore.case' %in% input$regex_options, ignore_case = 'ignore.case' %in% input$regex_options,
literal = 'fixed' %in% input$regex_options literal = 'fixed' %in% input$regex_options
print(x) 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 ---- # ---- Server - Tab - Help ----
HELP_DEFAULT_TEXT <- c( HELP_DEFAULT_TEXT <- c(
"<h3>Welcome to RegExplain</h3>", "<h3>Welcome to RegExplain</h3>",


observeEvent(input$help_try_this_hs_colors_text, { observeEvent(input$help_try_this_hs_colors_text, {
color_match <- "\\b(red|orange|yellow|green|blue|purple)\\b|red" 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, { observeEvent(input$help_try_this_hs_colors_pattern, {
}) })


observeEvent(input$help_try_this_hs_words_text, { 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, { observeEvent(input$help_try_this_hs_words_pattern, {
}) })


observeEvent(input$help_try_this_hs_refs_text, { 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, { observeEvent(input$help_try_this_hs_refs_pattern, {

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

res <- purrr::map_chr(res, function(resi) { res <- purrr::map_chr(res, function(resi) {
result_pad <- "" result_pad <- ""
if (grepl("pad\\d{2}", resi)) { 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) { if (max_pad_level - 3 > 0) {
result_pad <- sprintf("pad%02d", max_pad_level - 3) result_pad <- sprintf("pad%02d", max_pad_level - 3)
} }

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