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.
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:
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:
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:
Yes, you can set the error option to use one of the
search functions:
The searcher package itself doesn’t directly handle
warnings, but the companion package errorist
provides this functionality:
searcher?The package provides dedicated functions for interacting with AI assistants:
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:
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:
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:
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:
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:
ellmer
when:
These 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:
If the AI responses aren’t focused on R, try:
Using a more specific prompt:
Setting a system-level prompt:
Including “in R” explicitly in your queries:
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.