Title: | Find Pattern in Files |
---|---|
Description: | Creates a HTML widget which displays the results of searching for a pattern in files in a given folder. The results can be viewed in the 'RStudio' viewer pane, included in a 'R Markdown' document or in a 'Shiny' application. Also provides a 'Shiny' application allowing to run this widget and to navigate in the files found by the search. Instead of creating a HTML widget, it is also possible to get the results of the search in a 'tibble'. The search is performed by the 'grep' command-line utility. |
Authors: | Stéphane Laurent [aut, cre], Rob Burns [ctb, cph] ('ansi-to-html' library) |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 0.5.0 |
Built: | 2024-10-25 04:16:50 UTC |
Source: | https://github.com/stla/findinfiles |
Returns the results of findInFiles
in a
dataframe, when the option output = "viewer+tibble"
or
output = "tibble"
is used.
FIF2dataframe(fif)
FIF2dataframe(fif)
fif |
the output of |
The results of findInFiles
in a dataframe.
folder <- system.file("example", package = "findInFiles") fif <- findInFiles("R", "function", root = folder, output = "viewer+tibble") FIF2dataframe(fif) fif
folder <- system.file("example", package = "findInFiles") fif <- findInFiles("R", "function", root = folder, output = "viewer+tibble") FIF2dataframe(fif) fif
Returns the results of findInFiles
in a
tibble, when the option output = "viewer+tibble"
is used.
FIF2tibble(fif)
FIF2tibble(fif)
fif |
the output of |
The results of findInFiles
in a tibble.
folder <- system.file("example", package = "findInFiles") fif <- findInFiles("R", "function", root = folder, output = "viewer+tibble") FIF2tibble(fif) fif
folder <- system.file("example", package = "findInFiles") fif <- findInFiles("R", "function", root = folder, output = "viewer+tibble") FIF2tibble(fif) fif
Find a pattern in some files. The functions findInFiles
and fif
are the same, and fifR(...)
is the same as
findInFiles(extensions = "R", ...)
.
findInFiles( extensions, pattern, depth = NULL, maxCountPerFile = NULL, maxCount = NULL, wholeWord = FALSE, ignoreCase = FALSE, extended = FALSE, fixed = FALSE, perl = FALSE, includePattern = NULL, excludePattern = NULL, excludeFoldersPattern = NULL, moreOptions = NULL, root = ".", output = "viewer", elementId = NULL ) fif( extensions, pattern, depth = NULL, maxCountPerFile = NULL, maxCount = NULL, wholeWord = FALSE, ignoreCase = FALSE, extended = FALSE, fixed = FALSE, perl = FALSE, includePattern = NULL, excludePattern = NULL, excludeFoldersPattern = NULL, moreOptions = NULL, root = ".", output = "viewer", elementId = NULL ) fifR(...)
findInFiles( extensions, pattern, depth = NULL, maxCountPerFile = NULL, maxCount = NULL, wholeWord = FALSE, ignoreCase = FALSE, extended = FALSE, fixed = FALSE, perl = FALSE, includePattern = NULL, excludePattern = NULL, excludeFoldersPattern = NULL, moreOptions = NULL, root = ".", output = "viewer", elementId = NULL ) fif( extensions, pattern, depth = NULL, maxCountPerFile = NULL, maxCount = NULL, wholeWord = FALSE, ignoreCase = FALSE, extended = FALSE, fixed = FALSE, perl = FALSE, includePattern = NULL, excludePattern = NULL, excludeFoldersPattern = NULL, moreOptions = NULL, root = ".", output = "viewer", elementId = NULL ) fifR(...)
extensions |
extension(s) of the files to include in the search
(case-sensitive), e.g. |
pattern |
pattern to search for, a regular expression, e.g.
|
depth |
depth of the search, |
maxCountPerFile |
maximum number of results per file, |
maxCount |
maximum number of results, |
wholeWord |
logical, whether to match the whole pattern |
ignoreCase |
logical, whether to ignore the case |
extended |
logical, whether the pattern given in the |
fixed |
logical, whether the pattern given in the |
perl |
logical, whether the pattern given in the |
includePattern |
this argument is ignored if |
excludePattern |
a pattern or a vector of patterns; files and folders whose name matches this pattern or one of these patterns will be excluded from search |
excludeFoldersPattern |
a pattern or a vector of patterns; folders whose name matches this pattern or one of these patterns will be excluded from search |
moreOptions |
additional options passed to the |
root |
path to the root directory to search from |
output |
one of |
elementId |
a HTML id, usually useless |
... |
arguments other than |
A tibble if output="tibble"
, otherwise a
htmlwidget
object.
library(findInFiles) folder <- system.file("example", package = "findInFiles") findInFiles("R", "function", root = folder) findInFiles("R", "function", root = folder, output = "tibble") fif <- findInFiles("R", "function", root = folder, output = "viewer+tibble") FIF2tibble(fif) FIF2dataframe(fif) fif folder <- system.file("www", "shared", package = "shiny") findInFiles( "css", "color", root = folder, excludePattern = c("*.min.css", "selectize*", "shiny*") )
library(findInFiles) folder <- system.file("example", package = "findInFiles") findInFiles("R", "function", root = folder) findInFiles("R", "function", root = folder, output = "tibble") fif <- findInFiles("R", "function", root = folder, output = "viewer+tibble") FIF2tibble(fif) FIF2dataframe(fif) fif folder <- system.file("www", "shared", package = "shiny") findInFiles( "css", "color", root = folder, excludePattern = c("*.min.css", "selectize*", "shiny*") )
Output and render functions for using findInFiles
within
Shiny applications and interactive Rmd documents.
FIFOutput(outputId, width = "100%", height = "400px") renderFIF(expr, env = parent.frame(), quoted = FALSE)
FIFOutput(outputId, width = "100%", height = "400px") renderFIF(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
a valid CSS unit (like |
expr |
an expression that generates a ' |
env |
the environment in which to evaluate |
quoted |
logical, whether |
FIFOutput
returns an output element that can be included in a
Shiny UI definition, and renderFIF
returns a
shiny.render.function
object that can be included in a Shiny server
definition.
library(findInFiles) library(shiny) onKeyDown <- HTML( 'function onKeyDown(event) {', ' var key = event.which || event.keyCode;', ' if(key === 13) {', ' Shiny.setInputValue(', ' "pattern", event.target.value, {priority: "event"}', ' );', ' }', '}' ) ui <- fluidPage( tags$head(tags$script(onKeyDown)), br(), sidebarLayout( sidebarPanel( selectInput( "ext", "Extension", choices = c("R", "js", "css") ), tags$div( class = "form-group shiny-input-container", tags$label( class = "control-label", "Pattern" ), tags$input( type = "text", class = "form-control", onkeydown = "onKeyDown(event);", placeholder = "Press Enter when ready" ) ), numericInput( "depth", "Depth (set -1 for unlimited depth)", value = 0, min = -1, step = 1 ), checkboxInput( "wholeWord", "Whole word" ), checkboxInput( "ignoreCase", "Ignore case" ) ), mainPanel( FIFOutput("results") ) ) ) server <- function(input, output){ output[["results"]] <- renderFIF({ req(input[["pattern"]]) findInFiles( extensions = isolate(input[["ext"]]), pattern = input[["pattern"]], depth = isolate(input[["depth"]]), wholeWord = isolate(input[["wholeWord"]]), ignoreCase = isolate(input[["ignoreCase"]]) ) }) } if(interactive()){ shinyApp(ui, server) }
library(findInFiles) library(shiny) onKeyDown <- HTML( 'function onKeyDown(event) {', ' var key = event.which || event.keyCode;', ' if(key === 13) {', ' Shiny.setInputValue(', ' "pattern", event.target.value, {priority: "event"}', ' );', ' }', '}' ) ui <- fluidPage( tags$head(tags$script(onKeyDown)), br(), sidebarLayout( sidebarPanel( selectInput( "ext", "Extension", choices = c("R", "js", "css") ), tags$div( class = "form-group shiny-input-container", tags$label( class = "control-label", "Pattern" ), tags$input( type = "text", class = "form-control", onkeydown = "onKeyDown(event);", placeholder = "Press Enter when ready" ) ), numericInput( "depth", "Depth (set -1 for unlimited depth)", value = 0, min = -1, step = 1 ), checkboxInput( "wholeWord", "Whole word" ), checkboxInput( "ignoreCase", "Ignore case" ) ), mainPanel( FIFOutput("results") ) ) ) server <- function(input, output){ output[["results"]] <- renderFIF({ req(input[["pattern"]]) findInFiles( extensions = isolate(input[["ext"]]), pattern = input[["pattern"]], depth = isolate(input[["depth"]]), wholeWord = isolate(input[["wholeWord"]]), ignoreCase = isolate(input[["ignoreCase"]]) ) }) } if(interactive()){ shinyApp(ui, server) }
Launches a Shiny application allowing to run
findInFiles
and to navigate in the results.
shinyFIF()
shinyFIF()
No returned value, just launches the Shiny application.
The packages listed in the Suggests field of the package description are required.