3

I'm interested in running ack search on a RStudio project directory that mostly contains *.R script files but also some project files and often *.git files.

Directory

The project folder structure created from a default Shiny application:

$ tree
.
├── SomeNosense.Rproj
├── server.R
└── ui.R

Search

Given this I'm interested in running a simple search for a word old across the *.R files only. The sample shiny app created as a defult projects has some strings where the word old is mentioned.

ack -i -rr 'Old'

I'm getting results that do not match what should correspond to ack --help-types, which shows:

--[no]rr           .R

Results

whereas my results for this command are very messy:

.Rproj.user/38B87E11/sdb/s-FEC4716C/28624A5C
7:    "folds" : "",

.Rproj.user/38B87E11/sdb/s-FEC4716C/8A580C19
3:    "contents" : "\n# This is the user-interface definition of a Shiny web application.\n# You can find out more about building applications with Shiny here:\n#\n# http://shiny.rstudio.com\n#\n\nlibrary(shiny)\n\nshinyUI(fluidPage(\n\n  # Application title\n  titlePanel(\"Old Faithful Geyser Data\"),\n\n  # Sidebar with a slider input for number of bins\n  sidebarLayout(\n    sidebarPanel(\n      sliderInput(\"bins\",\n                  \"Number of bins:\",\n                  min = 1,\n                  max = 50,\n                  value = 30)\n    ),\n\n    # Show a plot of the generated distribution\n    mainPanel(\n      plotOutput(\"distPlot\")\n    )\n  )\n))\n",
7:    "folds" : "",

ui.R
13:  titlePanel("Old Faithful Geyser Data"),

Desired results

Desired results can be achieved with grep:

me-547/47:SomeNosense$ grep -r -i 'old' ~/Documents/SomeNosense/*.R
/Users/me/Documents/SomeNosense/ui.R:  titlePanel("Old Faithful Geyser Data"),

Question

What is wrong with my command that I'm not getting the same results?


The ag also seems to be returning more accurate results:

me-552/52:SomeNosense$ ag -rr -i 'old'
ui.R
13:  titlePanel("Old Faithful Geyser Data"),
me-553/53:SomeNosense$ ack -rr -i 'old'
.Rproj.user/38B87E11/sdb/per/t/28624A5C
7:    "folds" : "",

.Rproj.user/38B87E11/sdb/per/t/8A580C19
3:    "contents" : "\n# This is the user-interface definition of a Shiny web application.\n# You can find out more about building applications with Shiny here:\n#\n# http://shiny.rstudio.com\n#\n\nlibrary(shiny)\n\nshinyUI(fluidPage(\n\n  # Application title\n  titlePanel(\"Old Faithful Geyser Data\"),\n\n  # Sidebar with a slider input for number of bins\n  sidebarLayout(\n    sidebarPanel(\n      sliderInput(\"bins\",\n                  \"Number of bins:\",\n                  min = 1,\n                  max = 50,\n                  value = 30)\n    ),\n\n    # Show a plot of the generated distribution\n    mainPanel(\n      plotOutput(\"distPlot\")\n    )\n  )\n))\n",
7:    "folds" : "",

ui.R
13:  titlePanel("Old Faithful Geyser Data"),

RStudio: 1.0.143

  • 3
    Try ack with --rr (two dashes). -rr (one dash) means -r -r, which is essentially useless. – Satō Katsura Jul 15 '16 at 12:33
  • 2
    Same problem with ag: ag --r (two dashes, single r), rather than ag -rr (one dash, double r). – Satō Katsura Jul 15 '16 at 12:41
  • 2
    I'm the author of ack, and that -rr vs. --rr confusion is eye-opening. I'm trying to figure where I could put a mention of that somewhere in the docs. Thanks for answering, @SatoKatsura. – Andy Lester Jul 15 '16 at 17:02
  • 1
    @AndyLester I'd say the natural candidate would be output of ack --help-types. One definitely has to read that to find out the exact incantation for language X. :) – Satō Katsura Jul 15 '16 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.