Преглед изворни кода

Update documentation

tags/v0.2.0
Garrick Aden-Buie пре 8 година
родитељ
комит
004fcb437b
16 измењених фајлова са 95 додато и 39 уклоњено
  1. +2
    -0
      .Rbuildignore
  2. +6
    -4
      DESCRIPTION
  3. +1
    -1
      NAMESPACE
  4. +14
    -5
      R/regex_gadget.R
  5. +4
    -0
      R/regex_help.R
  6. +1
    -1
      R/regexplain-package.R
  7. +11
    -5
      R/run_regex.R
  8. +2
    -0
      R/shiny_modified_inputs.R
  9. +11
    -6
      R/utils.R
  10. +3
    -1
      man/regex_gadget.Rd
  11. +4
    -2
      man/regexplain-package.Rd
  12. +3
    -1
      man/regexplain_cheatsheet.Rd
  13. +8
    -11
      man/run_regex.Rd
  14. +3
    -0
      man/textAreaInputAlt.Rd
  15. +3
    -0
      man/textInputCode.Rd
  16. +19
    -2
      man/view_regex.Rd

+ 2
- 0
.Rbuildignore Прегледај датотеку

^.*\.Rproj$ ^.*\.Rproj$
^\.Rproj\.user$ ^\.Rproj\.user$
^LICENSE\.md$ ^LICENSE\.md$
^data-raw$
^docs$

+ 6
- 4
DESCRIPTION Прегледај датотеку

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

+ 1
- 1
NAMESPACE Прегледај датотеку



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)

+ 14
- 5
R/regex_gadget.R Прегледај датотеку

#' 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>&quot;\\\\\\\\&quot;</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>&quot;\\\\\\\\&quot;</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, {

+ 4
- 0
R/regex_help.R Прегледај датотеку

#' 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

+ 1
- 1
R/regexplain-package.R Прегледај датотеку

#' @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"

+ 11
- 5
R/run_regex.R Прегледај датотеку

#' #'
#' @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,

+ 2
- 0
R/shiny_modified_inputs.R Прегледај датотеку

#' #'
#' @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")

+ 11
- 6
R/utils.R Прегледај датотеку

escape_html <- function(x) {
x = gsub("&", "&amp;", x)
x = gsub("<", "&lt;", x)
x = gsub(">", "&gt;", x)
x = gsub("\"", "&quot;", x)
x = gsub(" ", "&nbsp;", 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('&', '&amp;', x)
x = gsub('<', '&lt;', x)
x = gsub('>', '&gt;', x)
x = gsub('"', '&quot;', 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"))

+ 3
- 1
man/regex_gadget.Rd Прегледај датотеку

\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.
} }

+ 4
- 2
man/regexplain-package.Rd Прегледај датотеку

\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]
} }



+ 3
- 1
man/regexplain_cheatsheet.Rd Прегледај датотеку

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.
} }

+ 8
- 11
man/run_regex.Rd Прегледај датотеку

\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

+ 3
- 0
man/textAreaInputAlt.Rd Прегледај датотеку

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}}
}

+ 3
- 0
man/textInputCode.Rd Прегледај датотеку

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}}
}

+ 19
- 2
man/view_regex.Rd Прегледај датотеку



\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)

} }

Loading…
Откажи
Сачувај