Skip to content

Commit b7d667c

Browse files
committed
Allowed non-error handler examples to be run for CRAN's checks.
1 parent fb905da commit b7d667c

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

R/search-functions.R

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
#' @param query Contents of string to search. Default is the error message.
1010
#' @param rlang Search for results written in R. Default is `TRUE`
1111
#'
12+
#' @return The generated search URL or an empty string.
13+
#'
1214
#' @rdname search_site
1315
#' @export
1416
#' @seealso [search_google()], [search_stackoverflow()], [search_github()],
1517
#' [search_bing()], [search_bitbucket()], [searcher()]
1618
#' @examples
17-
#' \dontrun{
1819
#' # Search in a generic way
19-
#' search_site("google", "r-project")
20+
#' search_site("r-project", "google")
2021
#'
2122
#' # Search Google
2223
#' search_google("r-project")
@@ -42,6 +43,7 @@
4243
#' # Search BitBucket for assertions
4344
#' search_bitbucket("assertions")
4445
#'
46+
#' \dontrun{
4547
#' # On error, automatically search the message on google
4648
#' options(error = searcher("google"))
4749
#' options(error = search_google)
@@ -102,12 +104,13 @@ search_site = function(query,
102104
#' To call the function, add a second set of parentheses.
103105
#'
104106
#' @examples
107+
#' ### Manually
108+
#' searcher("google")()
109+
#'
105110
#' \dontrun{
111+
#' ### Automatically
106112
#' # On error, automatically search the message on google
107113
#' options(error = searcher("google"))
108-
#'
109-
#' ### Manually
110-
#' searcher("google")()
111114
#' }
112115
searcher = function(site = c(
113116
"google",
@@ -136,8 +139,10 @@ rlang = TRUE) {
136139
#' See \url{https://moz.com/blog/the-ultimate-guide-to-the-google-search-parameters}
137140
#' for details.
138141
search_google = function(query = geterrmessage()) {
139-
if (!valid_query(query))
140-
return(invisible(NULL))
142+
if (!valid_query(query)) {
143+
message("Please provide only 1 `query` term that is not empty.")
144+
return(invisible(""))
145+
}
141146

142147
browse_url("https://google.com/search?q=", query)
143148
}
@@ -148,8 +153,10 @@ search_google = function(query = geterrmessage()) {
148153
#' The `search_bing()` function searches [Bing](https://bing.com) using:
149154
#' `https://bing.com/search?q=<query>`
150155
search_bing = function(query = geterrmessage()) {
151-
if (!valid_query(query))
152-
return(invisible(NULL))
156+
if (!valid_query(query)) {
157+
message("Please provide only 1 `query` term that is not empty.")
158+
return(invisible(""))
159+
}
153160

154161
browse_url("https://bing.com/search?q=", query)
155162
}
@@ -160,8 +167,10 @@ search_bing = function(query = geterrmessage()) {
160167
#' The `search_duckduckgo()` and `search_ddg()` functions both search
161168
#' [DuckDuckGo](https://duckduckgo.com) using: `https://duckduckgo.com/?q=<query>`
162169
search_duckduckgo = function(query = geterrmessage()) {
163-
if (!valid_query(query))
164-
return(invisible(NULL))
170+
if (!valid_query(query)) {
171+
message("Please provide only 1 `query` term that is not empty.")
172+
return(invisible(""))
173+
}
165174

166175
browse_url("https://duckduckgo.com/?q=", query)
167176
}
@@ -181,8 +190,10 @@ search_ddg = search_duckduckgo
181190
#' search interface please see:
182191
#' \url{https://stackoverflow.com/help/advanced-search-parameters-jobs}
183192
search_stackoverflow = function(query = geterrmessage(), rlang = TRUE) {
184-
if (!valid_query(query))
185-
return(invisible(NULL))
193+
if (!valid_query(query)) {
194+
message("Please provide only 1 `query` term that is not empty.")
195+
return(invisible(""))
196+
}
186197

187198
query = if (rlang)
188199
paste(query, "[r]")
@@ -207,8 +218,10 @@ search_so = search_stackoverflow
207218
#' \url{https://help.github.com/categories/searching-for-information-on-github/}
208219
#' and \url{https://help.github.com/articles/searching-code/}
209220
search_github = function(query = geterrmessage(), rlang = TRUE) {
210-
if (!valid_query(query))
211-
return(invisible(NULL))
221+
if (!valid_query(query)) {
222+
message("Please provide only 1 `query` term that is not empty.")
223+
return(invisible(""))
224+
}
212225

213226
query = if (rlang)
214227
paste(query, "language:r type:issue")
@@ -234,8 +247,10 @@ search_gh = search_github
234247
#' search interface please see:
235248
#' \url{https://confluence.atlassian.com/bitbucket/code-search-in-bitbucket-873876782.html}
236249
search_bitbucket = function(query = geterrmessage(), rlang = TRUE) {
237-
if (!valid_query(query))
238-
return(invisible(NULL))
250+
if (!valid_query(query)) {
251+
message("Please provide only 1 `query` term that is not empty.")
252+
return(invisible(""))
253+
}
239254

240255
query = if (rlang)
241256
paste(query, "lang:r")
@@ -247,12 +262,3 @@ search_bitbucket = function(query = geterrmessage(), rlang = TRUE) {
247262
#' @rdname search_site
248263
#' @export
249264
search_bb = search_bitbucket
250-
251-
valid_query = function(query) {
252-
if (missing(query) | is.null(query) |
253-
query == "" | is.expression(query)) {
254-
FALSE
255-
} else {
256-
TRUE
257-
}
258-
}

man/search_site.Rd

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/searcher-package.Rd

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/searcher.Rd

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)