knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE )
This vignette addresses common questions about using the searcher
package.
If you have a question not covered here, please consider opening an issue on
GitHub.
searcher
package?The searcher
package provides a search and query interface directly inside R.
It allows you to quickly search or inquiry about error messages, code examples,
or any query across multiple platforms including search engines,
developer communities, code repositories, and AI assistants.
# From CRAN (stable version) install.packages("searcher") # From GitHub (development version) if(!requireNamespace("remotes")) { install.packages("remotes") } remotes::install_github("coatless-rpkg/searcher")
searcher
instead of manually searching in a browser?searcher
offers several advantages:
searcher
support?The package supports multiple types of platforms:
Simply use any of the search functions with your query:
# Search Google search_google("ggplot2 themes") # Search StackOverflow search_stackoverflow("dplyr filter") # Search GitHub search_github("shiny dashboard")
By default, all search functions append R-specific terms to your queries. This
behavior is controlled by the rlang
parameter which is set to TRUE
by
default. If you want more general results, set rlang = FALSE
:
# R-specific results search_google("linear regression") # General results not limited to R search_google("linear regression", rlang = FALSE)
Different platforms have different strengths:
search_rseek()
) is a specialized search engine for R contentsearch_stackoverflow()
) is excellent for specific error messages and programming questionssearch_github()
) is useful for package-specific issuessearch_posit_community()
) is great for questions about RStudio, Shiny, and other Posit productsFor general searches, Google often provides the most comprehensive results, but you might prefer privacy-focused alternatives like DuckDuckGo or Brave.
If you've just encountered an error, all search functions will use the last error message as the default query if you don't specify one:
# This will search the last error message on Google search_google() # This will search the last error message on StackOverflow search_stackoverflow()
Yes, you can set the error
option to use one of the search functions:
# Automatically search errors on Google options(error = searcher("google")) # Automatically search errors on StackOverflow options(error = search_stackoverflow) # Automatically send errors to Claude AI options(error = ask_claude)
The searcher
package itself doesn't directly handle warnings, but the
companion package errorist
provides this functionality:
# Install errorist install.packages("errorist") # Set up errorist to search both errors and warnings errorist::errorist_enable()
searcher
?The package provides dedicated functions for interacting with AI assistants:
# Ask ChatGPT ask_chatgpt("How do I create a violin plot in ggplot2?") # Ask Claude ask_claude("Explain the difference between lapply and sapply") # Ask Perplexity ask_perplexity("What's the best approach for time series forecasting in R?")
No. The AI search functions open a browser tab with your query pre-filled on the respective AI service's web interface. This means:
You can customize AI responses using prompts in two ways:
1. Per-call prompts:
ask_chatgpt("How to merge data frames?", prompt = "Show examples using both base R and dplyr:")
2. Default prompts via options:
options(searcher.claude_prompt = "As an R expert, provide clear code examples:") # Now all Claude queries will use this prompt ask_claude("How to handle missing data?")
3. System-level prompts:
# Use a built-in prompt ai_prompt("debugging") # Now all AI assistants will use the debugging prompt ask_claude("Error: object 'mtcrs' not found") # Set a system-level prompt ai_prompt("As an R educator, explain this concept in detail:") # Now all AI assistants will use this prompt ask_chatgpt("What is the tidyverse?")
See vignette("using-ai-assistants-with-searcher", "searcher")
for more details on
effective prompting.
The prompt management system in searcher
allows you to create, store, and
apply sophisticated prompts when working with AI assistants. This helps you get
more consistent and helpful responses.
The package comes with several pre-defined prompts for different scenarios:
# List available prompts ai_prompt_list() # Set the "debugging" prompt as active ai_prompt("debugging") # Now use any AI assistant with this prompt ask_claude("Error: object 'mtcrs' not found")
Yes, you can either use custom prompt text directly or add it to the prompt library:
# Use custom text directly ai_prompt("As an R package developer, explain this error in detail:") # Add to the prompt library ai_prompt_register( "tidyverse_expert", "As a tidyverse expert, provide modern data manipulation solutions:" ) # Use your registered prompt ai_prompt("tidyverse_expert")
For more details, see vignette("managing-ai-prompts", "searcher")
.
searcher
?You can set various options to customize the package behavior:
# In your .Rprofile or at the start of your session options( # Launch browser after a delay (in seconds) searcher.launch_delay = 0.2, # Use RStudio's viewer pane instead of a browser searcher.use_rstudio_viewer = TRUE, # Default keyword suffix (base or tidyverse) searcher.default_keyword = "tidyverse", # Default prompts for AI services searcher.chatgpt_prompt = "You are an R educator...", searcher.claude_prompt = "As an R expert..." )
You can change the default keyword suffix used in searches by setting the
searcher.default_keyword
option:
# In your .Rprofile or at the start of your session options(searcher.default_keyword = "tidyverse")
This will modify the keywords appended to your searches to target tidyverse-related content instead of base R.
By default, there's a 0.5-second delay before opening a browser. You can adjust this:
# Shorter delay (0.2 seconds) options(searcher.launch_delay = 0.2) # No delay options(searcher.launch_delay = 0) # Longer delay (1 second) options(searcher.launch_delay = 1)
searcher
's AI assistant integration differ from the ellmer
package?Both searcher
and ellmer
provide ways to
integrate AI assistance into your R workflow, but they take different approaches
and have different strengths:
searcher
: Opens a web browser with your query pre-filled in the
AI service's web interface. This means:
ellmer
: Uses API connections to interact with AI models directly from R.
This generally means:
searcher
when:You're asking exploratory questions or conducting research
Use ellmer
when:
searcher
: Offers a prompt management system for web interfacesellmer
: Typically provides direct control over prompts in API callsThese packages can be complementary rather than competitive:
searcher
for exploratory work, debugging, and researchellmer
for production code, reproducible workflows, and batch processingIf you're building AI capabilities into an R package or application,
ellmer
's API approach may be more suitable. For interactive use during
data analysis or debugging, searcher
's browser approach may be more convenient.
This could be due to several issues:
options(searcher.launch_delay = 1)
If you want to search a specific error rather than the most recent one, you need to explicitly provide the error message:
search_google("Error: object 'specific_error' not found")
If the AI responses aren't focused on R, try:
Using a more specific prompt:
r
ask_claude("How to join tables?", prompt = "I'm specifically asking about R dplyr joins.")
Setting a system-level prompt:
r
ai_prompt("As an R programming expert, all my questions are about R unless specified otherwise.")
Including "in R" explicitly in your queries:
r
ask_chatgpt("How to join tables in R?")
searcher
in non-interactive scripts?Yes, but the browser opening functionality will be disabled in non-interactive sessions. The functions will still return the search URLs, which can be useful in logs or notifications.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.