searcher

Query Search Portals and AI Assistants from R

https://github.com/coatless-rpkg/searcher

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.5%) to scientific vocabulary

Keywords

automatic error-handling error-messages r search-engine search-portals
Last synced: 6 months ago · JSON representation

Repository

Query Search Portals and AI Assistants from R

Basic Info
Statistics
  • Stars: 79
  • Watchers: 3
  • Forks: 6
  • Open Issues: 3
  • Releases: 6
Topics
automatic error-handling error-messages r search-engine search-portals
Created over 8 years ago · Last pushed 9 months ago
Metadata Files
Readme Changelog

README.Rmd

---
output: github_document
---



```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)
```

# searcher A hexagonal logo for searcher


[![R-CMD-check](https://github.com/coatless-rpkg/searcher/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/coatless-rpkg/searcher/actions/workflows/R-CMD-check.yaml)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/searcher)](https://www.r-pkg.org/pkg/searcher)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/searcher)](https://cran.r-project.org/package=searcher)


### Overview 

The goal of `searcher` is to provide a search interface directly inside of _R_.
For example, to look up  `rcpp example numeric vector`
or `ggplot2 fix axis labels` call one of the `search_*()` functions to
automatically have a web browser open, go to a search site, and type the query.
`searcher` also provides direct integration with AI assistants through `ask_*()`
functions, allowing you to send queries to ChatGPT, Claude, and other AI services
with R-optimized prompts.

By default, the search and ask functions will attempt to search the last error
on call if no query is specified.

![Example workflow of searching and asking AI assistants questions from R.](https://i.imgur.com/Zq2rg6G.gif)

## Installation

The `searcher` package is available on both 
[CRAN](https://CRAN.R-project.org/package=searcher) and 
[GitHub](https://github.com/coatless-rpkg/searcher). The 
[CRAN](https://CRAN.R-project.org/package=searcher)
version is considered stable while the [GitHub](https://github.com/coatless-rpkg/searcher) 
version is in a state of development and may break. 

You can install the stable version of the `searcher` package with:

```r
install.packages("searcher")
```

For the development version, you can opt for:

```r
if(!requireNamespace("remotes")) { install.packages("remotes") }
remotes::install_github("coatless-rpkg/searcher")
```

## Usage

```r
library(searcher)
```

## Search Terms

The `search_*()` functions can be used to search a query directly from _R_ on
major search engines, programming help websites, and code repositories. The following search
platforms are supported: [Google](https://www.google.com), [Bing](https://www.bing.com/),
[DuckDuckGo](https://duckduckgo.com/), [Startpage](https://www.startpage.com/en/),
Ecosia, [rseek](https://rseek.org/), Qwant, [Brave](https://search.brave.com/), 
Kagi, X (formerly Twitter), [BlueSky](https://bsky.app), [Mastodon](https://mastodon.social),
[StackOverflow](https://stackoverflow.com/), 
[Posit Community](https://forum.posit.co/), 
[GitHub](https://github.com/search), [grep.app](https://grep.app/), 
and [BitBucket](https://bitbucket.org/product/).
By default, an appropriate suffix for each platform that ensures relevant 
results to _R_ is appended to all queries. This behavior can be disabled by 
using `rlang = FALSE`.

```r
# Searching R project on major search engines
search_google("R project")
search_bing("R project")
search_ecosia("R project")
search_rseek("R project")
search_qwant("R project")
search_brave("R project")
search_kagi("R project")
search_duckduckgo("R project")                           # or search_ddg(...)
search_startpage("R project")                            # or search_sp(...)

# Searching X/Twitter to find out about machine learning for R and in general
search_twitter("machine learning")
search_twitter("machine learning", rlang = FALSE)

# Searching BlueSky to find out about deep learning for R and in general
search_bluesky("deep learning")
search_bluesky("deep learning", rlang = FALSE)

# Searching Mastodon to find out about data visualization for R and in general
search_mastodon("data vis")
search_mastodon("data vis", rlang = FALSE)

# Searching SO for linear regression questions for R and in general
search_stackoverflow("linear regression")
search_stackoverflow("linear regression", rlang = FALSE) # or search_so(...)

# Searching Posit Community for tips
search_posit_community("tips")
search_posit_community("tips", rlang = FALSE)          # or search_posit(...)

# Searching GitHub code for graphs in R and other languages
search_grep("graph")
search_grep("graph", rlang = FALSE)

# Searching GitHub Issues for maps in R and other languages
search_github("maps")
search_github("maps", rlang = FALSE)                     # or search_gh(...)

# Searching BitBucket for assertions in R and other languages
search_bitbucket("assertions")
search_bitbucket("assertions", rlang = FALSE)            # or search_bb(...)
```

## AI Assistants

The package also provides functions to query AI assistants directly from R.
The following AI Assistant platforms are supported: OpenAI's [ChatGPT](https://chatgpt.com/),
Anthropic's [Claude](https://claude.ai/),
[Perplexity](https://www.perplexity.ai/),
Microsoft (Bing)'s [Copilot](https://copilot.microsoft.com/), 
Mistral's [le Chat](https://chat.mistral.ai/chat), 
xAI's [Grok](https://grok.com/), and [Meta.ai](https://www.meta.ai/).
These functions open a browser with your query pre-filled, using customizable
prompts that help the AI give more effective responses for R programming:

```r
# Get coding help from AI assistants
ask_chatgpt("How to create a ggplot scatterplot with regression line?")
ask_claude("Explain what purrr::map_df does")
ask_perplexity("Compare dplyr vs data.table performance")
ask_mistral("How to handle missing data in R?")
ask_bing_copilot("Write a function to calculate the median")
ask_grok("What is better base R or tidyverse for research?")
ask_meta_ai("What are the best R packages for time series analysis?")

# Search with an error message
tryCatch(
  cor(mtcrs),  # Intentional typo
  error = function(e) ask_claude()  # Will search the error message
)
```

All AI search functions accept an optional `prompt` parameter that guides how
the AI responds:

```r
# Adding specific instructions to the prompt
ask_chatgpt(
  "Fix this code: ggplot(mtcars, aes(x=mpg, y=hp) + geom_point()", 
  prompt = "You are an R debugging expert. Explain what's wrong step by step."
)
```

See `vignette("using-ai-assistants-with-searcher",  package = "searcher")` for more
details on using AI assistants in searches through `searcher`.

## AI Prompt Management

For those who frequently use AI assistants, searcher provides a prompt management system:

```r
# List available prompts
ai_prompt_list()

# Set a system-level prompt for all AI services
ai_prompt("debugging")  # Use a predefined prompt for debugging

# Create custom prompts
ai_prompt_register("my_prompt", "As an R expert analyzing the mtcars dataset...")

# Check active prompt
ai_prompt_active()

# Clear active prompt
ai_prompt_clear()
```

See `vignette("managing-ai-prompts")` for more details on the prompt management system.


### Comparison with ellmer Package

While both `searcher` and `ellmer` provide AI assistance for R users, they take different approaches:

- `searcher` opens a web browser with your query pre-filled in the AI service's interface
  - No API keys needed   
  - Works with multiple AI services   
  - Visual interface for complex interactions   
  - Requires browser access and being logged in
- `ellmer` uses API connections to interact with models directly within R
  - Requires API keys
  - Results returned directly to R console/environment
  - Better for programmatic/automated use
  - Works in non-interactive environments

These packages are **complementary** rather than competitive:

- Use `searcher` for interactive exploration, debugging, and research
- Use `ellmer` for reproducible workflows, batch processing, and production code

See `vignette("faq", package = "searcher")` for a more detailed comparison.

## Search Errors

`searcher` offers preliminary support for automatically or manually 
searching errors that are generated in _R_. For more robust error search
support and to also search warning messages, please use the
[`errorist`](https://github.com/coatless-rpkg/errorist) package.

### Automatically 

Searching the last error automatically is possible by registering a function
as _R_'s error handler via either `searcher(site="")` or one of the `search_*()`
functions.  Thus, when an error occurs, this function will automatically be called. This 
triggers a new browser window to open with the error term listed in verbatim.

```r
# Using the generic search error handler
options(error = searcher("google"))

# Directly specify the search or ask function
options(error = search_google)

options(error = ask_claude)
```

### Manually

Alternatively, these functions can also be used manually so that the default
error dispatch is preserved. In the manual case, you will have to explicitly
call the search function. After that, a browser window will open with
the last error message as the search query on the desired search portal.

```r
# Search the last error message with Google
search_google()

# Ask an AI assistant about the last error
## Switch into debug mode
ai_prompt("debugging")

## Ask Claude about the last error
ask_claude()
```

## Package Customizations

The ability to customize different operations in `searcher` is possible by
setting values in [`options()`](https://stat.ethz.ch/R-manual/R-patched/RHOME/library/base/html/options.html)
within [`~/.Rprofile`](https://stat.ethz.ch/R-manual/R-patched/library/base/html/Startup.html).
Presently, the following options are available:

- `searcher.launch_delay`: Amount of time between launching the web browser
  from when the command was issued. Default is `0.5` seconds.
- `searcher.use_rstudio_viewer`: Display search results in the RStudio
   viewer pane instead of a web browser. Default is `FALSE`.
- `searcher.default_keyword`: Suffix keyword to focus search results
  between either `"base"` or `"tidyverse"`. Default is `"base"`.
- AI service prompts:
  - `searcher.chatgpt_prompt`: Default prompt for OpenAI's ChatGPT queries.
  - `searcher.claude_prompt`: Default prompt for Anthropic's Claude queries.
  - `searcher.perplexity_prompt`: Default prompt for Perplexity AI queries.
  - `searcher.mistral_prompt`: Default prompt for Mistral AI queries.
  - `searcher.bing_copilot_prompt`: Default prompt for Bing Copilot queries.
  - `searcher.grok_prompt`: Default prompt for xAI's Grok AI queries.
  - `searcher.meta_ai_prompt`: Default prompt for Meta AI queries.

To set one of these options, please create the `.Rprofile` by typing into _R_:

```r
file.edit("~/.Rprofile")
```

From there, add:

```r
.First = function() {
  options(
    searcher.launch_delay       = 0,
    searcher.use_rstudio_viewer = FALSE,
    searcher.default_keyword    = "tidyverse",
    searcher.chatgpt_prompt     = "You are an R programming expert. Please provide concise answers with code examples.",
    ## Additional options.
  )
}
```

## Motivation

The idea for `searcher` began as a project to automatically search errors and
warnings that occurred while working with _R_ after a conversation 
among [Dirk Eddelbuettel](http://dirk.eddelbuettel.com), 
[Barry Rowlingson](http://barry.rowlingson.com), and myself. However, there was 
no search interface that allowed querying directly from _R_ outside of the built-in [`utils::RSiteSearch()`](https://stat.ethz.ch/R-manual/R-devel/library/utils/html/RSiteSearch.html),
which only queries , and the
[`sos`](https://cran.r-project.org/package=sos) 
package, which queries an off-site user premade database. Both of these options
were focused solely on querying _R_ documentation made available by packages.
Given the nature of errors generally being _undocumented_, neither of these
approaches could be used. Thus, `searcher` was unintentionally born to
provide a means for [`errorist`](https://github.com/coatless-rpkg/errorist), which
contains a robust way to automatically searching errors and warnings.

### Special Thanks

- [Dirk Eddelbuettel](http://dirk.eddelbuettel.com) for starting the discussion
  on [XKCD Comic 1185: Ineffective Sorts](https://xkcd.com/1185/).
- [Barry Rowlingson](http://barry.rowlingson.com) for remarks about functionality.

### Publicity

On the `#rstats`-twitter verse (c.f. `https://twitter.com/search?q=%23rstats`), `searcher` has been positively received by
community members.

> R package "searcher" that automatically searches Stackoverflow for error that
> you just saw in the console. Cool package, especially for those who learn R :)
> https://github.com/coatless-rpkg/searcher ... #r #rlang #rstats #rstudio
>
> --- Paweł Przytuła 
> March 23th, 2019. ~292 Retweets and 876 likes (Note, URL updated to new repository location.)

> Did you know, using "searcher" package, you could automatically to
> search stackoverflow, google, GitHub and many more sites for errors,
> packages or topics. #rstats
>
> --- Shakirah Nakalungi (c.f. `https://twitter.com/cynthia_kyra`) June 29th, 2019, when she was Rotating Curator for the "We are R-Ladies" twitter account (c.f. `https://twitter.com/WeAreRLadies/status/1144921174251581440`)
> ~144 Retweets and 544 likes

Please let us know via an [issue ticket](https://github.com/coatless-rpkg/searcher/issues/new)
about how you are using `searcher`.

## License

GPL (>= 2)

Owner

  • Name: coatless-rpkg
  • Login: coatless-rpkg
  • Kind: organization

GitHub Events

Total
  • Create event: 10
  • Release event: 1
  • Issues event: 6
  • Watch event: 6
  • Delete event: 7
  • Issue comment event: 3
  • Push event: 39
  • Pull request event: 17
Last Year
  • Create event: 10
  • Release event: 1
  • Issues event: 6
  • Watch event: 6
  • Delete event: 7
  • Issue comment event: 3
  • Push event: 39
  • Pull request event: 17

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 64
  • Total Committers: 2
  • Avg Commits per committer: 32.0
  • Development Distribution Score (DDS): 0.016
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
James J Balamuta j****a@g****m 63
Alex Rossell Hayes 4****s 1

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 21
  • Total pull requests: 18
  • Average time to close issues: 4 months
  • Average time to close pull requests: about 7 hours
  • Total issue authors: 5
  • Total pull request authors: 2
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.22
  • Merged pull requests: 18
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • coatless (6)
  • schneiderpy (1)
Pull Request Authors
  • coatless (11)
Top Labels
Issue Labels
question (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 289 last-month
  • Total docker downloads: 20,358
  • Total dependent packages: 2
  • Total dependent repositories: 2
  • Total versions: 6
  • Total maintainers: 1
cran.r-project.org: searcher

Query Search Interfaces

  • Versions: 6
  • Dependent Packages: 2
  • Dependent Repositories: 2
  • Downloads: 289 Last month
  • Docker Downloads: 20,358
Rankings
Stargazers count: 5.1%
Forks count: 9.6%
Docker downloads count: 12.6%
Dependent packages count: 13.7%
Average: 14.4%
Dependent repos count: 19.3%
Downloads: 26.2%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.3.0 depends
  • covr * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat >= 2.1.0 suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/pr-fetch v1 composite
  • r-lib/actions/pr-push v1 composite
  • r-lib/actions/setup-r v1 composite