Skip to content

Commit c7a2327

Browse files
committed
Initial build
0 parents  commit c7a2327

13 files changed

+571
-0
lines changed

.Rbuildignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
^README\.Rmd$
4+
^README-.*\.png$
5+
^\.travis\.yml$

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.DS_Store

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
2+
3+
language: R
4+
sudo: false
5+
cache: packages

DESCRIPTION

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Package: searcher
2+
Title: Search Error Messages Directly from R
3+
Version: 0.0.1
4+
Authors@R: c(person("James", "Balamuta", email = "[email protected]", role = c("aut", "cre")),
5+
person("Dirk", "Eddelbuettel", email = "[email protected]", role = c("ctb")),
6+
person("Barry", "Rowlingson", email = "[email protected]", role = c("ctb","med")))
7+
Description: This package provides a search interface for R to search error messages
8+
on Google, StackOverflow, GitHub, Bing, or BitBucket. As an added bonus,
9+
this package can hook into R's error apparatus to capture the error message
10+
and automatically search the error message.
11+
Depends: R (>= 3.0.0)
12+
License: GPL (>= 2)
13+
Encoding: UTF-8
14+
LazyData: true
15+
RoxygenNote: 6.0.1

NAMESPACE

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(search_bing)
4+
export(search_bitbucket)
5+
export(search_duckduckgo)
6+
export(search_error)
7+
export(search_github)
8+
export(search_google)
9+
export(search_site)
10+
export(search_stackoverflow)
11+
importFrom(utils,URLencode)
12+
importFrom(utils,browseURL)

R/search_func.R

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#' Open a Web Browser with URL
2+
#'
3+
#' Open a web browser with a given URL.
4+
#'
5+
#' @param base The URL prefix e.g. `https://google.com/search?q=`
6+
#' @param unencoded_query An unencoded string that must be encoded with [utils::URLencode].
7+
#' @param encoded_query An encoded string that satisifies [utils::URLencode].
8+
#' @importFrom utils browseURL URLencode
9+
#' @seealso [utils::browseURL], [utils::URLencode]
10+
open_browser = function(base, unencoded_query, encoded_query = "") {
11+
12+
encodedURL = paste0(base, URLencode(unencoded_query), encoded_query)
13+
14+
browseURL(encodedURL)
15+
}
16+
17+
#' Search a Message Using a Search Engine
18+
#'
19+
#' Searches message using a search engine.
20+
#' @param site Name of site to search on. Supported options:
21+
#' `"google"` (default), `"stackoverflow"`, `"github"`, `"bing"`,
22+
#' `"bitbucket"`
23+
#' @param query Contents of string to search. Default is the error message.
24+
#' @param rlang Search for results written in R. Default is `TRUE`
25+
#' @rdname search_error
26+
#' @export
27+
#' @seealso [search_google], [search_stackoverflow], [search_github],
28+
#' [search_bing], [search_bitbucket], [search_error], [open_browser]
29+
#' @examples
30+
#' \dontrun{
31+
#' # On error, automatically search the message on google
32+
#' options(error = search_google)
33+
#'
34+
#' # Search in a generic way
35+
#' search_site("google", "r-project")
36+
#'
37+
#' # Search Google
38+
#' search_google("r-project")
39+
#'
40+
#' # Search Bing
41+
#' search_bing("Microsoft R")
42+
#'
43+
#' # Search DuckDuckGo
44+
#' search_duckduckgo("R language")
45+
#'
46+
#' # Search StackOverflow for Convolutions in the r tag
47+
#' search_stackoverflow("convolutions")
48+
#'
49+
#' # Search all languages on StackOverflow for convolutions
50+
#' search_stackoverflow("convolutions", rlang = FALSE)
51+
#'
52+
#' # Search GitHub Issues for bivariate normal in the language:r
53+
#' search_github("bivariate normal")
54+
#'
55+
#' # Search all languages on GitHub Issues for bivariate normal
56+
#' search_github("bivariate normal", rlang = FALSE)
57+
#'
58+
#' # Search BitBucket for assertions
59+
#' search_bitbucket("assertions")
60+
#' }
61+
search_site = function(site, query, rlang = TRUE){
62+
switch(tolower(site),
63+
"google" = search_google(query),
64+
"stackoverflow" = search_stackoverflow(query, rlang),
65+
"github" = search_github(query, rlang),
66+
"bitbucket" = search_bitbucket(query, rlang),
67+
"bing" = search_bing(query),
68+
"duckduckgo" = search_duckduckgo(query),
69+
search_google(query)
70+
)
71+
}
72+
73+
#' @rdname search_error
74+
#' @export
75+
#' @section Generic Error Search:
76+
#' The `search_error` function grabs the last error message and
77+
#' tries to search it. This function will ensure that R language
78+
#' is the primary search context.
79+
search_error = function(site, query = geterrmessage()) {
80+
search_site(site, query, rlang = TRUE)
81+
}
82+
83+
#' @rdname search_error
84+
#' @export
85+
#' @section Google Search:
86+
#' The `search_google` function searches [Google](https://google.com) using:
87+
#' `https://google.com/search?q=<Error>`
88+
#' See <https://moz.com/blog/the-ultimate-guide-to-the-google-search-parameters>
89+
#' for details.
90+
search_google = function(query = geterrmessage()) {
91+
open_browser("https://google.com/search?q=", query)
92+
}
93+
94+
#' @rdname search_error
95+
#' @export
96+
#' @section Bing Search:
97+
#' The `search_bing` function searches [Bing](https://bing.com) using:
98+
#' `https://bing.com/search?q=<Error>`
99+
search_bing = function(query = geterrmessage()) {
100+
open_browser("https://bing.com/search?q=", query)
101+
}
102+
103+
#' @rdname search_error
104+
#' @export
105+
#' @section DuckDuckGo Search:
106+
#' The `search_duckduckgo` function searches [DuckDuckGo](https://duckduckgo.com) using:
107+
#' `https://duckduckgo.com/?q=<Error>`
108+
search_duckduckgo = function(query = geterrmessage()) {
109+
open_browser("https://duckduckgo.com/?q=", query)
110+
}
111+
112+
#' @rdname search_error
113+
#' @export
114+
#' @section StackOverflow Search:
115+
#' The `search_stackoverflow` function searches [StackOverflow](https://stackoverflow.com) using:
116+
#' `https://stackoverflow.com/search?q=%5Br%5D+<Error>`
117+
#' See <https://stackoverflow.com/help/advanced-search-parameters-jobs>
118+
search_stackoverflow = function(query = geterrmessage(), rlang = TRUE) {
119+
query = if(rlang) paste(query, "[r]") else query
120+
open_browser("https://stackoverflow.com/search?q=", query)
121+
}
122+
123+
#' @rdname search_error
124+
#' @export
125+
#' @section GitHub Search:
126+
#' The `search_github` function searches [GitHub](https://github.com) using:
127+
#' `https://github.com/search?q=<Error>+language%3Ar+type%3Aissue&type=Issues`
128+
#' See <https://help.github.com/categories/searching-for-information-on-github/>
129+
#' and <https://help.github.com/articles/searching-code/>
130+
search_github = function(query = geterrmessage(), rlang = TRUE) {
131+
query = if(rlang) paste(query, "language:r type:issue") else query
132+
133+
open_browser("https://github.com/search?q=", query, "&type=Issues")
134+
}
135+
136+
137+
#' @rdname search_error
138+
#' @export
139+
#' @section BitBucket Search:
140+
#' The `search_bitbucket` function searches [BitBucket](https://bitbucket.com) using:
141+
#' `https://bitbucket.com/search?q=lang%3Ar+<Error>`
142+
#' See <https://confluence.atlassian.com/bitbucket/code-search-in-bitbucket-873876782.html>
143+
search_bitbucket = function(query = geterrmessage(), rlang = TRUE) {
144+
query = if(rlang) paste(query, "lang:r") else query
145+
open_browser("https://bitbucket.com/search?q=", query)
146+
}

R/searcher-package.R

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#' @details
2+
#' Provides an interface to search websites via R.
3+
"_PACKAGE"

README.Rmd

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
output:
3+
md_document:
4+
variant: markdown_github
5+
---
6+
7+
<!-- README.md is generated from README.Rmd. Please edit that file -->
8+
9+
```{r, echo = FALSE}
10+
knitr::opts_chunk$set(
11+
collapse = TRUE,
12+
comment = "#>",
13+
fig.path = "README-"
14+
)
15+
```
16+
17+
[![Travis-CI Build Status](https://travis-ci.org/coatless/searcher.svg?branch=master)](https://travis-ci.org/coatless/searcher)[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/searcher)](http://www.r-pkg.org/pkg/searcher)[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/searcher)](https://cran.r-project.org/package=searcher)
18+
19+
# searcher
20+
21+
The goal of searcher is to provide a search interface for _R_ errors among the
22+
search portals. As an added bonus, the functions can also be used to directly
23+
search other terms such as `UIUC` or `mcmc rcpp`.
24+
25+
![](https://media.giphy.com/media/l378bwNTMR8DejX0I/giphy.gif)
26+
27+
## Installation
28+
29+
The `searcher` package is only available on GitHub for the moment. You can
30+
install the `searcher` package with:
31+
32+
```r
33+
devtools::install_github("coatless/searcher")
34+
```
35+
36+
## Usage
37+
38+
```r
39+
library(searcher)
40+
```
41+
42+
## Search Errors
43+
44+
### Automatically
45+
46+
Searching the last error automatically is possible by registering one of the
47+
`search_` functions as the error handler. Thus, when an error occurs,
48+
this function will automatically be called. This triggers a new browser
49+
window to open with the error term listed in verbatim.
50+
51+
```r
52+
# Directly specify the search function
53+
options(error = search_github)
54+
options(error = search_google)
55+
56+
# Using the generic search error handler
57+
options(error = search_error("google"))
58+
```
59+
60+
### Manually
61+
62+
Alternatively, these functions can also be used manually so that the default
63+
error dispatch is preserved. In the manual case, you will have to explicitly
64+
call the search function. After that, a browser window will open with
65+
the last error message as the search query on the desired search portal.
66+
67+
```r
68+
search_google()
69+
search_bing()
70+
search_duckduckgo() # or search_ddg()
71+
search_stackoverflow() # or search_so()
72+
search_github() # or search_gh()
73+
search_bitbucket() # or search_bb()
74+
```
75+
76+
## Search Terms
77+
78+
As an added bonus, the search functions can be used to trigger a search directly
79+
from _R_ on major search engines. In particular, you can supply your own
80+
query directly.
81+
82+
```r
83+
# Searching R project on major search engines
84+
search_google("R project")
85+
search_bing("R project")
86+
search_duckduckgo("R project")
87+
88+
# Searching for linear regression questions for R and in general
89+
search_stackoverflow("linear regression")
90+
search_stackoverflow("linear regression", rlang = FALSE)
91+
92+
# Searching GitHub Issues for maps in R and other languages
93+
search_github("maps")
94+
search_github("maps", rlang = FALSE)
95+
96+
# Searching BitBucket for assertions in R and other languages
97+
search_bitbucket("assertions")
98+
search_bitbucket("assertions", rlang = FALSE)
99+
```
100+
101+
# License
102+
103+
GPL (>= 2)

README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!-- README.md is generated from README.Rmd. Please edit that file -->
2+
[![Travis-CI Build Status](https://travis-ci.org/coatless/searcher.svg?branch=master)](https://travis-ci.org/coatless/searcher)[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/searcher)](http://www.r-pkg.org/pkg/searcher)[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/searcher)](https://cran.r-project.org/package=searcher)
3+
4+
searcher
5+
========
6+
7+
The goal of searcher is to provide a search interface for *R* errors among the search portals. As an added bonus, the functions can also be used to directly search other terms such as `UIUC` or `mcmc rcpp`.
8+
9+
![](https://media.giphy.com/media/l378bwNTMR8DejX0I/giphy.gif)
10+
11+
Installation
12+
------------
13+
14+
The `searcher` package is only available on GitHub for the moment. You can install the `searcher` package with:
15+
16+
``` r
17+
devtools::install_github("coatless/searcher")
18+
```
19+
20+
Usage
21+
-----
22+
23+
``` r
24+
library(searcher)
25+
```
26+
27+
Search Errors
28+
-------------
29+
30+
### Automatically
31+
32+
Searching the last error automatically is possible by registering one of the `search_` functions as the error handler. 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.
33+
34+
``` r
35+
# Directly specify the search function
36+
options(error = search_github)
37+
options(error = search_google)
38+
39+
# Using the generic search error handler
40+
options(error = search_error("google"))
41+
```
42+
43+
### Manually
44+
45+
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.
46+
47+
``` r
48+
search_google()
49+
search_bing()
50+
search_duckduckgo() # or search_ddg()
51+
search_stackoverflow() # or search_so()
52+
search_github() # or search_gh()
53+
search_bitbucket() # or search_bb()
54+
```
55+
56+
Search Terms
57+
------------
58+
59+
As an added bonus, the search functions can be used to trigger a search directly from *R* on major search engines. In particular, you can supply your own query directly.
60+
61+
``` r
62+
# Searching R project on major search engines
63+
search_google("R project")
64+
search_bing("R project")
65+
search_duckduckgo("R project")
66+
67+
# Searching for linear regression questions for R and in general
68+
search_stackoverflow("linear regression")
69+
search_stackoverflow("linear regression", rlang = FALSE)
70+
71+
# Searching GitHub Issues for maps in R and other languages
72+
search_github("maps")
73+
search_github("maps", rlang = FALSE)
74+
75+
# Searching BitBucket for assertions in R and other languages
76+
search_bitbucket("assertions")
77+
search_bitbucket("assertions", rlang = FALSE)
78+
```
79+
80+
License
81+
=======
82+
83+
GPL (&gt;= 2)

0 commit comments

Comments
 (0)