-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
234 lines (184 loc) · 8.74 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# searcher
<!-- badges: start -->
[![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)
<!-- badges: end -->
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.
By default, the search functions will attempt to search the last error on call
if no query is specified.
![](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, X (formerly Twitter), [StackOverflow](https://stackoverflow.com/),
[RStudio Community](https://community.rstudio.com/search),
[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_duckduckgo("R project") # or search_ddg(...)
search_startpage("R project") # or search_sp(...)
# Searching Twitter to find out about machine learning for R and in general
search_twitter("machine learning")
search_twitter("machine learning", rlang = FALSE)
# Searching for linear regression questions for R and in general
search_stackoverflow("linear regression")
search_stackoverflow("linear regression", rlang = FALSE) # or search_so(...)
# Searching RStudio Community for tips
search_rstudio_community("tips")
search_rstudio_community("tips", rlang = FALSE) # or search_rscom(...)
# 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(...)
```
## 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 function
options(error = search_github)
options(error = search_google)
```
### 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_google()
search_bing()
search_ecosia()
search_rseek()
search_qwant()
search_twitter()
search_grep()
search_duckduckgo() # or search_ddg()
search_startpage() # or search_sp()
search_stackoverflow() # or search_so()
search_rstudio_community() # or search_rscom()
search_github() # or search_gh()
search_bitbucket() # or search_bb()
```
## 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"`.
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"
## 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 <http://search.r-project.org/>, 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)