| ^.*\.Rproj$ | ^.*\.Rproj$ | ||||
| ^\.Rproj\.user$ | ^\.Rproj\.user$ | ||||
| ^LICENSE\.md$ | ^LICENSE\.md$ | ||||
| ^data-raw$ | |||||
| ^docs$ |
| Authors@R: c( | Authors@R: c( | ||||
| person("Garrick", "Aden-Buie", email = "g.adenbuie@gmail.com", role = c("aut", "cre")), | person("Garrick", "Aden-Buie", email = "g.adenbuie@gmail.com", role = c("aut", "cre")), | ||||
| person("Winston", "Chang", role = c("ctb"), comment = "Author of textInput and textAreaInput fragments from shiny"), | person("Winston", "Chang", role = c("ctb"), comment = "Author of textInput and textAreaInput fragments from shiny"), | ||||
| person("Yihui", "Xie", role = c("ctb"), comment = "Author of escape_html fragment from highr"), | |||||
| person(family = "RStudio", role = "cph", comment = "Copyright holder of included shiny fragments") | person(family = "RStudio", role = "cph", comment = "Copyright holder of included shiny fragments") | ||||
| ) | ) | ||||
| Description: A set of RStudio Addins to help interactively test and build | Description: A set of RStudio Addins to help interactively test and build | ||||
| regular expressions. Provides a Shiny gadget interface for interactively | regular expressions. Provides a Shiny gadget interface for interactively | ||||
| constructing the regexp and viewing the results from common string-searching | |||||
| functions. Also provides a helpful reference sheet as an RStudio addin. | |||||
| Depends: R (>= 3.4) | |||||
| constructing the regular expression and viewing the results from common | |||||
| string-searching functions. The gadget interface includes a helpful | |||||
| regex syntax reference sheet and a library of common patterns. | |||||
| Depends: R (>= 3.2) | |||||
| License: GPL-3 | License: GPL-3 | ||||
| Encoding: UTF-8 | Encoding: UTF-8 | ||||
| LazyData: true | LazyData: true | ||||
| utils, | utils, | ||||
| tidyr, | tidyr, | ||||
| rstudioapi, | rstudioapi, | ||||
| shiny, | |||||
| shiny (>= 0.13), | |||||
| miniUI, | miniUI, | ||||
| jsonlite, | jsonlite, | ||||
| rematch2 | rematch2 |
| export(regex_gadget) | export(regex_gadget) | ||||
| export(regexplain_cheatsheet) | export(regexplain_cheatsheet) | ||||
| export(run_regex) | |||||
| export(view_regex) | export(view_regex) | ||||
| import(miniUI) | import(miniUI) | ||||
| import(shiny) | import(shiny) | ||||
| importFrom(dplyr,summarize) | importFrom(dplyr,summarize) | ||||
| importFrom(rlang,.data) | importFrom(rlang,.data) | ||||
| importFrom(utils,getFromNamespace) | importFrom(utils,getFromNamespace) | ||||
| importFrom(utils,globalVariables) | |||||
| importFrom(utils,installed.packages) | importFrom(utils,installed.packages) | ||||
| importFrom(utils,packageVersion) | importFrom(utils,packageVersion) |
| #' RegExplain gadget | #' RegExplain gadget | ||||
| #' | #' | ||||
| #' The function behind the RegExplain Selection and RegExplain File | |||||
| #' addins. Opens the RegExplain gadget interface in an RStudio viewer | |||||
| #' pane. | |||||
| #' | |||||
| #' @import miniUI | #' @import miniUI | ||||
| #' @import shiny | #' @import shiny | ||||
| #' @param text Text to explore in gadget (editable using interface) | #' @param text Text to explore in gadget (editable using interface) | ||||
| #' @param start_page Open gadget to this tab, one of `"Text"`, `"RegEx"`, | #' @param start_page Open gadget to this tab, one of `"Text"`, `"RegEx"`, | ||||
| #' `"Output"`, or `"Help"` | #' `"Output"`, or `"Help"` | ||||
| #' @export | #' @export | ||||
| regex_gadget <- function(text = NULL, | |||||
| start_page = if (is.null(text)) "Text" else "RegEx") { | |||||
| regex_gadget <- function( | |||||
| text = NULL, | |||||
| start_page = if (is.null(text)) "Text" else "RegEx" | |||||
| ) { | |||||
| stopifnot(requireNamespace("miniUI"), requireNamespace("shiny")) | stopifnot(requireNamespace("miniUI"), requireNamespace("shiny")) | ||||
| update_available <- check_version() | update_available <- check_version() | ||||
| observe({ | observe({ | ||||
| if (getOption('regexplain.debug.gadget.text', FALSE)) { | if (getOption('regexplain.debug.gadget.text', FALSE)) { | ||||
| cat("\npattern: ", rtext()) | |||||
| cat("\ntext :", rtext()) | |||||
| } | } | ||||
| if (getOption('regexplain.debug.gadget.pattern', FALSE)) { | if (getOption('regexplain.debug.gadget.pattern', FALSE)) { | ||||
| cat("\npattern: ", pattern()) | |||||
| cat("\npattern:", pattern()) | |||||
| } | } | ||||
| if (getOption('regexplain.debug.gadget.replacement', FALSE)) { | if (getOption('regexplain.debug.gadget.replacement', FALSE)) { | ||||
| cat("\npattern: ", replacement()) | |||||
| cat("\nreplace:", replacement()) | |||||
| } | } | ||||
| cat("\n") | cat("\n") | ||||
| }) | }) | ||||
| "<p>An extra backslash is still needed to match a literal <code>\\</code> in standard regular expressions. This means that you will need to enter <code>\\\\</code> in the <strong>RegEx</strong> tab, and the output to R will be <code>"\\\\\\\\"</code>.</p>" | "<p>An extra backslash is still needed to match a literal <code>\\</code> in standard regular expressions. This means that you will need to enter <code>\\\\</code> in the <strong>RegEx</strong> tab, and the output to R will be <code>"\\\\\\\\"</code>.</p>" | ||||
| ) | ) | ||||
| # avoid CRAN check NOTES | |||||
| help_text <- NULL # in help_server.R | |||||
| make_help_tab_text <- NULL # in help_server.R | |||||
| source(system.file("shiny", "help_server.R", package = "regexplain"), local = TRUE) | source(system.file("shiny", "help_server.R", package = "regexplain"), local = TRUE) | ||||
| observeEvent(input$help_resources, { | observeEvent(input$help_resources, { |
| #' Regex Cheatsheet Quick Reference | #' Regex Cheatsheet Quick Reference | ||||
| #' | #' | ||||
| #' The function behind the RegExplain Cheatsheet addin. Opens a summary of | |||||
| #' regular expression syntax -- the RegExplain cheatsheet -- in an RStudio | |||||
| #' viewer pane. | |||||
| #' | |||||
| #' @import miniUI | #' @import miniUI | ||||
| #' @import shiny | #' @import shiny | ||||
| #' @export | #' @export |
| #' @importFrom dplyr "%>%" mutate filter group_by summarize select | #' @importFrom dplyr "%>%" mutate filter group_by summarize select | ||||
| #' @importFrom utils getFromNamespace installed.packages packageVersion | |||||
| #' @importFrom utils getFromNamespace installed.packages packageVersion globalVariables | |||||
| #' @importFrom rlang .data | #' @importFrom rlang .data | ||||
| #' @keywords internal | #' @keywords internal | ||||
| "_PACKAGE" | "_PACKAGE" |
| #' | #' | ||||
| #' @param text Text to search | #' @param text Text to search | ||||
| #' @param pattern regexp | #' @param pattern regexp | ||||
| #' @inheritParams base::regexec | |||||
| #' @export | |||||
| #' @inheritDotParams base::regexec ignore.case perl fixed useBytes | |||||
| run_regex <- function( | run_regex <- function( | ||||
| text, | text, | ||||
| pattern, | pattern, | ||||
| ignore.case = FALSE, | ignore.case = FALSE, | ||||
| perl = FALSE, | perl = FALSE, | ||||
| fixed = FALSE, | fixed = FALSE, | ||||
| useBytes = FALSE, | |||||
| invert = FALSE | |||||
| useBytes = FALSE | |||||
| ) { | ) { | ||||
| # Use regex to get matches by group, gives start index and length | # Use regex to get matches by group, gives start index and length | ||||
| m <- regexec(pattern, text, ignore.case, perl, fixed, useBytes) | m <- regexec(pattern, text, ignore.case, perl, fixed, useBytes) | ||||
| #' View grouped regex results | #' View grouped regex results | ||||
| #' | #' | ||||
| #' View the result of the regular expression when applied to the given text. | |||||
| #' The default behavior renders the result as HTML and opens the file in | |||||
| #' the RStudio viewer pane. If `render` is `FALSE`, the HTML itself is returned. | |||||
| #' If the output is destined for a [knitr] document, set `knitr` to `TRUE`. | |||||
| #' | |||||
| #' @examples | |||||
| #' view_regex("example", "amp", render=FALSE) | |||||
| #' | |||||
| #' @param text Text to search | #' @param text Text to search | ||||
| #' @param pattern Regex pattern to look for | #' @param pattern Regex pattern to look for | ||||
| #' @param render Render results to an HTML doc and open in RStudio viewer? | #' @param render Render results to an HTML doc and open in RStudio viewer? | ||||
| #' the double `\\\\` required for escaping backslashes in R. When `FALSE`, | #' the double `\\\\` required for escaping backslashes in R. When `FALSE`, | ||||
| #' regex is displayed as interpreted by the regex engine (i.e. double `\\\\` | #' regex is displayed as interpreted by the regex engine (i.e. double `\\\\` | ||||
| #' as a single `\\`). | #' as a single `\\`). | ||||
| #' @param ... Passed to [run_regex()] | |||||
| #' @inheritDotParams base::regexec ignore.case perl fixed useBytes | |||||
| #' @export | #' @export | ||||
| view_regex <- function( | view_regex <- function( | ||||
| text, | text, |
| #' | #' | ||||
| #' @inheritParams shiny::textAreaInput | #' @inheritParams shiny::textAreaInput | ||||
| #' @param is_code Should the text input be considered verbatim code input? | #' @param is_code Should the text input be considered verbatim code input? | ||||
| #' @family modified shiny inputs | |||||
| textAreaInputAlt <- function(inputId, label, value = "", width = NULL, height = NULL, | textAreaInputAlt <- function(inputId, label, value = "", width = NULL, height = NULL, | ||||
| cols = NULL, rows = NULL, placeholder = NULL, resize = NULL, | cols = NULL, rows = NULL, placeholder = NULL, resize = NULL, | ||||
| is_code = TRUE) { | is_code = TRUE) { | ||||
| #' | #' | ||||
| #' @inheritParams shiny::textInput | #' @inheritParams shiny::textInput | ||||
| #' @param width Width of `shiny-input-container` div. | #' @param width Width of `shiny-input-container` div. | ||||
| #' @family modified shiny inputs | |||||
| textInputCode <- function(inputId, label, value = "", width = NULL, | textInputCode <- function(inputId, label, value = "", width = NULL, | ||||
| placeholder = NULL) { | placeholder = NULL) { | ||||
| `%AND%` <- getFromNamespace("%AND%", "shiny") | `%AND%` <- getFromNamespace("%AND%", "shiny") |
| escape_html <- function(x) { | |||||
| x = gsub("&", "&", x) | |||||
| x = gsub("<", "<", x) | |||||
| x = gsub(">", ">", x) | |||||
| x = gsub("\"", """, x) | |||||
| x = gsub(" ", " ", x) | |||||
| # highr:::escape_html | |||||
| # by Yihui Xie, GPL license | |||||
| # https://github.com/yihui/highr/blob/4f54a5b8960d6246daadacea1020ebcdc458ce50/R/utils.R#L54-L61 | |||||
| escape_html = function(x) { | |||||
| x = gsub('&', '&', x) | |||||
| x = gsub('<', '<', x) | |||||
| x = gsub('>', '>', x) | |||||
| x = gsub('"', '"', x) | |||||
| x | x | ||||
| } | } | ||||
| escape_backslash <- function(x) { | escape_backslash <- function(x) { | ||||
| gsub("\\\\", "\\\\\\\\", x) | gsub("\\\\", "\\\\\\\\", x) | ||||
| } | } | ||||
| # avoid CRAN note for tidyr::gather in wrap_results | |||||
| utils::globalVariables(c("end", "loc", "start", "type")) |
| \code{"Output"}, or \code{"Help"}} | \code{"Output"}, or \code{"Help"}} | ||||
| } | } | ||||
| \description{ | \description{ | ||||
| RegExplain gadget | |||||
| The function behind the RegExplain Selection and RegExplain File | |||||
| addins. Opens the RegExplain gadget interface in an RStudio viewer | |||||
| pane. | |||||
| } | } |
| \description{ | \description{ | ||||
| A set of RStudio Addins to help interactively test and build | A set of RStudio Addins to help interactively test and build | ||||
| regular expressions. Provides a Shiny gadget interface for interactively | regular expressions. Provides a Shiny gadget interface for interactively | ||||
| constructing the regexp and viewing the results from common string-searching | |||||
| functions. Also provides a helpful reference sheet as an RStudio addin. | |||||
| constructing the regular expression and viewing the results from common | |||||
| string-searching functions. The gadget interface includes a helpful | |||||
| regex syntax reference sheet and a library of common patterns. | |||||
| } | } | ||||
| \seealso{ | \seealso{ | ||||
| Useful links: | Useful links: | ||||
| Other contributors: | Other contributors: | ||||
| \itemize{ | \itemize{ | ||||
| \item Winston Chang (Author of textInput and textAreaInput fragments from shiny) [contributor] | \item Winston Chang (Author of textInput and textAreaInput fragments from shiny) [contributor] | ||||
| \item Yihui Xie (Author of escape_html fragment from highr) [contributor] | |||||
| \item RStudio (Copyright holder of included shiny fragments) [copyright holder] | \item RStudio (Copyright holder of included shiny fragments) [copyright holder] | ||||
| } | } | ||||
| regexplain_cheatsheet() | regexplain_cheatsheet() | ||||
| } | } | ||||
| \description{ | \description{ | ||||
| Regex Cheatsheet Quick Reference | |||||
| The function behind the RegExplain Cheatsheet addin. Opens a summary of | |||||
| regular expression syntax -- the RegExplain cheatsheet -- in an RStudio | |||||
| viewer pane. | |||||
| } | } |
| \title{Extract matched groups from regexp} | \title{Extract matched groups from regexp} | ||||
| \usage{ | \usage{ | ||||
| run_regex(text, pattern, ignore.case = FALSE, perl = FALSE, fixed = FALSE, | run_regex(text, pattern, ignore.case = FALSE, perl = FALSE, fixed = FALSE, | ||||
| useBytes = FALSE, invert = FALSE) | |||||
| useBytes = FALSE) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{text}{Text to search} | \item{text}{Text to search} | ||||
| \item{pattern}{regexp} | \item{pattern}{regexp} | ||||
| \item{ignore.case}{if \code{FALSE}, the pattern matching is \emph{case | |||||
| \item{...}{Arguments passed on to \code{base::regexec} | |||||
| \describe{ | |||||
| \item{ignore.case}{if \code{FALSE}, the pattern matching is \emph{case | |||||
| sensitive} and if \code{TRUE}, case is ignored during matching.} | sensitive} and if \code{TRUE}, case is ignored during matching.} | ||||
| \item{perl}{logical. Should Perl-compatible regexps be used?} | |||||
| \item{fixed}{logical. If \code{TRUE}, \code{pattern} is a string to be | |||||
| \item{perl}{logical. Should Perl-compatible regexps be used?} | |||||
| \item{fixed}{logical. If \code{TRUE}, \code{pattern} is a string to be | |||||
| matched as is. Overrides all conflicting arguments.} | matched as is. Overrides all conflicting arguments.} | ||||
| \item{useBytes}{logical. If \code{TRUE} the matching is done | |||||
| \item{useBytes}{logical. If \code{TRUE} the matching is done | |||||
| byte-by-byte rather than character-by-character. See | byte-by-byte rather than character-by-character. See | ||||
| \sQuote{Details}.} | \sQuote{Details}.} | ||||
| \item{invert}{logical. If \code{TRUE} return indices or values for | |||||
| elements that do \emph{not} match.} | |||||
| }} | |||||
| } | } | ||||
| \description{ | \description{ | ||||
| Extract matched groups from regexp | Extract matched groups from regexp |
| code font style for the input text and with \code{autocomplete}, \code{autocorrect}, | code font style for the input text and with \code{autocomplete}, \code{autocorrect}, | ||||
| \code{autocapitalize} and \code{spellcheck} set to \code{off} or \code{false}. | \code{autocapitalize} and \code{spellcheck} set to \code{off} or \code{false}. | ||||
| } | } | ||||
| \seealso{ | |||||
| Other modified shiny inputs: \code{\link{textInputCode}} | |||||
| } |
| font style for the input text and with \code{autocomplete}, \code{autocorrect}, | font style for the input text and with \code{autocomplete}, \code{autocorrect}, | ||||
| \code{autocapitalize} and \code{spellcheck} set to \code{off} or \code{false}. | \code{autocapitalize} and \code{spellcheck} set to \code{off} or \code{false}. | ||||
| } | } | ||||
| \seealso{ | |||||
| Other modified shiny inputs: \code{\link{textAreaInputAlt}} | |||||
| } |
| \item{pattern}{Regex pattern to look for} | \item{pattern}{Regex pattern to look for} | ||||
| \item{...}{Passed to \code{\link[=run_regex]{run_regex()}}} | |||||
| \item{...}{Arguments passed on to \code{base::regexec} | |||||
| \describe{ | |||||
| \item{ignore.case}{if \code{FALSE}, the pattern matching is \emph{case | |||||
| sensitive} and if \code{TRUE}, case is ignored during matching.} | |||||
| \item{perl}{logical. Should Perl-compatible regexps be used?} | |||||
| \item{fixed}{logical. If \code{TRUE}, \code{pattern} is a string to be | |||||
| matched as is. Overrides all conflicting arguments.} | |||||
| \item{useBytes}{logical. If \code{TRUE} the matching is done | |||||
| byte-by-byte rather than character-by-character. See | |||||
| \sQuote{Details}.} | |||||
| }} | |||||
| \item{render}{Render results to an HTML doc and open in RStudio viewer?} | \item{render}{Render results to an HTML doc and open in RStudio viewer?} | ||||
| as a single \code{\\}).} | as a single \code{\\}).} | ||||
| } | } | ||||
| \description{ | \description{ | ||||
| View grouped regex results | |||||
| View the result of the regular expression when applied to the given text. | |||||
| The default behavior renders the result as HTML and opens the file in | |||||
| the RStudio viewer pane. If \code{render} is \code{FALSE}, the HTML itself is returned. | |||||
| If the output is destined for a \link{knitr} document, set \code{knitr} to \code{TRUE}. | |||||
| } | |||||
| \examples{ | |||||
| view_regex("example", "amp", render=FALSE) | |||||
| } | } |