From 53700a833702ffee5308172c1f486fbdf41c6ee2 Mon Sep 17 00:00:00 2001 From: James J Balamuta Date: Thu, 4 Jul 2019 19:09:08 -0500 Subject: [PATCH] Add search_rstudio_community (close #13) (#17) * Add search portal for RStudio Community * Update DESCRIPTION with new portal * Add a unit test for RSC. * Update the README with RStudio Com add * Update news and roll a new version --- DESCRIPTION | 24 +++++---- NAMESPACE | 2 + NEWS.md | 16 ++++-- R/search-functions.R | 99 +++++++++++++++++++++++----------- README.Rmd | 23 +++++--- README.md | 28 ++++++---- man/search_site.Rd | 33 +++++++++--- man/searcher-package.Rd | 10 ++-- man/searcher.Rd | 9 ++-- tests/testthat/test-searcher.R | 21 +++++++- 10 files changed, 184 insertions(+), 81 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7cd7680..ef11e28 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,20 @@ Package: searcher Title: Query Search Interfaces -Version: 0.0.3.9100 -Authors@R: c(person("James", "Balamuta", - email = "balamut2@illinois.edu", role = c("aut", "cre"), - comment = c(ORCID = "0000-0003-2826-8458"))) +Version: 0.0.3.9200 +Authors@R: c( + person("James", "Balamuta", + email = "balamut2@illinois.edu", + role = c("aut", "cre"), + comment = c(ORCID = "0000-0003-2826-8458") + ) + ) Description: Provides a search interface to look up terms - on 'Google', 'Bing', 'DuckDuckGo', 'Startpage', 'StackOverflow', 'GitHub', - and 'BitBucket'. Upon searching, a browser window will open with the - aforementioned search results. -URL: https://github.com/coatless/searcher -BugReports: https://github.com/coatless/searcher/issues -Depends: R (>= 3.0.0) + on 'Google', 'Bing', 'DuckDuckGo', 'Startpage', 'StackOverflow', + 'RStudio Community', 'GitHub', and 'BitBucket'. Upon searching, a browser + window will open with the aforementioned search results. +URL: https://github.com/r-assist/searcher +BugReports: https://github.com/r-assist/searcher/issues +Depends: R (>= 3.3.0) License: GPL (>= 2) Encoding: UTF-8 LazyData: true diff --git a/NAMESPACE b/NAMESPACE index c9c1885..52f73c9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,8 @@ export(search_gh) export(search_github) export(search_google) export(search_ixquick) +export(search_rscom) +export(search_rstudio_community) export(search_site) export(search_so) export(search_sp) diff --git a/NEWS.md b/NEWS.md index 0e48d61..692af66 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,16 @@ -# searcher 0.0.3.9000 +# searcher 0.0.3.9200 + +## Features + +- Added search portal: + - `search_rstudio_community()` or `search_rscom()`: Searches on [RStudio Community](https://community.rstudio.com/search). + (#13, #17) ## Changes -- Renamed search portal `search_ixquick()` to `search_startpage()` due to the - merging of ixquick into startpage. (#15) +- Renamed search portal: + - Changed `search_ixquick()` to `search_startpage()` due to the + merging of ixquick into startpage. (#15) - Update the README overview for the project. (#16) ## Deployment @@ -16,7 +23,8 @@ ## Features -- Added search portal `search_ixquick()`: Searches with [ixquick](https://www.ixquick.com/). (#8, #6) +- Added search portal: + - `search_ixquick()`: Searches with [ixquick](https://www.ixquick.com/). (#8, #6) ## Changes diff --git a/R/search-functions.R b/R/search-functions.R index ee4f778..618bb28 100644 --- a/R/search-functions.R +++ b/R/search-functions.R @@ -3,19 +3,20 @@ #' Creates an appropriate query string for a search engine and then opens #' up the resulting page in a web browser. #' -#' @param site Name of site to search on. Supported options: -#' `"google"` (default), `"bing"`, `"duckduckgo"`, `"startpage"`, -#' `"stackoverflow"`, `"github"`, and `"bitbucket"`. -#' @param query Contents of string to search. Default is the error message. -#' @param rlang Search for results written in R. Default is `TRUE` +#' @param site Name of site to search on. Supported options: +#' `"google"` (default), `"bing"`, `"duckduckgo"`, `"startpage"`, +#' `"stackoverflow"`, `"rstudio community"`, `"github"`, and +#' `"bitbucket"`. +#' @param query Contents of string to search. Default is the error message. +#' @param rlang Search for results written in R. Default is `TRUE` #' #' @return The generated search URL or an empty string. #' #' @rdname search_site #' @export #' @seealso [search_google()], [search_bing()], [search_duckduckgo()], -#' [search_startpage()], [search_stackoverflow()], [search_github()], -#' [search_bitbucket()], [searcher()] +#' [search_startpage()], [search_stackoverflow()], [search_rstudio_community()], +#' [search_github()], [search_bitbucket()], and [searcher()] #' @examples #' # Search in a generic way #' search_site("r-project", "google") @@ -38,6 +39,9 @@ #' # Search all languages on StackOverflow for convolutions #' search_stackoverflow("convolutions", rlang = FALSE) #' +#' # Search RStudio Community +#' search_rstudio_community("RStudio IDE") +#' #' # Search GitHub Issues for bivariate normal in the language:r #' search_github("bivariate normal") #' @@ -56,16 +60,18 @@ search_site = function(query, site = c( "google", "bing", + "duckduckgo", + "ddg", + "startpage", + "sp", "stackoverflow", "so", + "rstudio community", + "rscom", "github", "gh", - "duckduckgo", - "ddg", "bitbucket", - "bb", - "startpage", - "sp" + "bb" ), rlang = TRUE) { site = tolower(site) @@ -74,21 +80,19 @@ search_site = function(query, switch( site, google = search_google(query, rlang), - stackoverflow = , - # empty case carried below - so = search_stackoverflow(query, rlang), - github = , - # empty case carried below - gh = search_github(query, rlang), - bitbucket = , - # empty case carried below - bb = search_bitbucket(query, rlang), bing = search_bing(query, rlang), - duckduckgo = , - # empty case carried below + duckduckgo = , # empty case carried below ddg = search_duckduckgo(query, rlang), - startpage = , - sp = search_startpage(query, rlang) + startpage = , # empty case carried below + sp = search_startpage(query, rlang), + stackoverflow = , # empty case carried below + so = search_stackoverflow(query, rlang), + `rstudio community` = , # empty case carried below + rscom = search_rstudio_community(query, rlang), + github = , # empty case carried below + gh = search_github(query, rlang), + bitbucket = , # empty case carried below + bb = search_bitbucket(query, rlang) ) } @@ -122,16 +126,18 @@ search_site = function(query, searcher = function(site = c( "google", "bing", + "duckduckgo", "ddg", + "startpage", "sp", - "so", - "gh", - "bb", - "duckduckgo", "stackoverflow", + "so", + "rstudio community", + "rscom", "github", + "gh", "bitbucket", - "startpage" + "bb" ), rlang = TRUE) { function(query = geterrmessage(), rlang = rlang) { @@ -232,7 +238,7 @@ search_sp = search_startpage ########################### End Search Engines -########################### Start Search Code Repos +########################### Start Search Development Community Websites #' @rdname search_site #' @export @@ -259,6 +265,36 @@ search_stackoverflow = function(query = geterrmessage(), rlang = TRUE) { #' @export search_so = search_stackoverflow +#' @rdname search_site +#' @export +#' @section RStudio Community Search: +#' The `search_rstudio_community()` and `search_rscom()` functions both search +#' [RStudio Community](https://community.rstudio.com/) using: +#' \code{https://community.rstudio.com/search?q=} +#' +#' For additional details regarding [RStudio Community](https://community.rstudio.com/)'s +#' search interface please see the [Discourse](https://discourse.org) API documentation: +#' \url{https://docs.discourse.org/#tag/Search} +search_rstudio_community = function(query = geterrmessage(), rlang = TRUE) { + if (!valid_query(query)) { + message("Please provide only 1 `query` term that is not empty.") + return(invisible("")) + } + + # Disable using a query check + # query = append_r_suffix(query, rlang = rlang, "[r]") + + browse_url("https://community.rstudio.com/search?q=", query) +} + +#' @rdname search_site +#' @export +search_rscom = search_rstudio_community + +########################### End Search Development Community Websites + +########################### Start Search Code Repos + #' @rdname search_site #' @export #' @section GitHub Search: @@ -285,7 +321,6 @@ search_github = function(query = geterrmessage(), rlang = TRUE) { #' @export search_gh = search_github - #' @rdname search_site #' @export #' @section BitBucket Search: diff --git a/README.Rmd b/README.Rmd index 2853be4..3e0a2a0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -22,10 +22,11 @@ knitr::opts_chunk$set( # searcher The goal of `searcher` is to provide a search interface directly inside of _R_. -For example, within _R_, there is now the ability to look up -`rcpp example numeric vector` or `ggplot2 fix axis labels` without having to +For example, within _R_, it is possible to look up `rcpp example numeric vector` +or `ggplot2 fix axis labels` without having to open a browser, go to a search site, and type the query. By default, -the search functions automatically search the last error on call. +the search functions automatically search the last error on call if no +query is specified. ![](https://i.imgur.com/Zq2rg6G.gif) @@ -61,6 +62,7 @@ major search engines, code repositories, and help websites. The following search platforms are supported: [Google](https://google.com), [Bing](https://www.bing.com/), [DuckDuckGo](https://duckduckgo.com/), [Startpage](https://www.startpage.com/en/), [StackOverflow](https://stackoverflow.com/search), +[RStudio Community](https://community.rstudio.com/search), [GitHub](https://github.com/search), and [BitBucket](https://bitbucket.com/search). 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 @@ -77,6 +79,10 @@ search_startpage("R project") # or search_sp(...) 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 Issues for maps in R and other languages search_github("maps") search_github("maps", rlang = FALSE) # or search_gh(...) @@ -120,11 +126,12 @@ the last error message as the search query on the desired search portal. ```r search_google() search_bing() -search_duckduckgo() # or search_ddg() -search_startpage() # or search_sp() -search_stackoverflow() # or search_so() -search_github() # or search_gh() -search_bitbucket() # or search_bb() +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() ``` diff --git a/README.md b/README.md index a748c6a..3529fa2 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,11 @@ coverage](https://codecov.io/gh/r-assist/searcher/branch/master/graph/badge.svg) # searcher The goal of `searcher` is to provide a search interface directly inside -of *R*. For example, within *R*, there is now the ability to look up -`rcpp example numeric vector` or `ggplot2 fix axis labels` without -having to open a browser, go to a search site, and type the query. By -default, the search functions automatically search the last error on -call. +of *R*. For example, within *R*, it is possible to look up `rcpp example +numeric vector` or `ggplot2 fix axis labels` without having to open a +browser, go to a search site, and type the query. By default, the search +functions automatically search the last error on call if no query is +specified. ![](https://i.imgur.com/Zq2rg6G.gif) @@ -55,7 +55,8 @@ The `search_*()` functions can be used to search a query directly from following search platforms are supported: [Google](https://google.com), [Bing](https://www.bing.com/), [DuckDuckGo](https://duckduckgo.com/), [Startpage](https://www.startpage.com/en/), -[StackOverflow](https://stackoverflow.com/search), +[StackOverflow](https://stackoverflow.com/search), [RStudio +Community](https://community.rstudio.com/search), [GitHub](https://github.com/search), and [BitBucket](https://bitbucket.com/search). By default, an appropriate suffix for each platform that ensures relevant results to *R* is @@ -73,6 +74,10 @@ search_startpage("R project") # or search_sp(...) 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 Issues for maps in R and other languages search_github("maps") search_github("maps", rlang = FALSE) # or search_gh(...) @@ -117,11 +122,12 @@ search portal. ``` r search_google() search_bing() -search_duckduckgo() # or search_ddg() -search_startpage() # or search_sp() -search_stackoverflow() # or search_so() -search_github() # or search_gh() -search_bitbucket() # or search_bb() +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() ``` # Motivation diff --git a/man/search_site.Rd b/man/search_site.Rd index 51ce9ae..837a7e6 100644 --- a/man/search_site.Rd +++ b/man/search_site.Rd @@ -11,15 +11,17 @@ \alias{search_sp} \alias{search_stackoverflow} \alias{search_so} +\alias{search_rstudio_community} +\alias{search_rscom} \alias{search_github} \alias{search_gh} \alias{search_bitbucket} \alias{search_bb} \title{Search a Query on a Search Portal in a Web Browser} \usage{ -search_site(query, site = c("google", "bing", "stackoverflow", "so", - "github", "gh", "duckduckgo", "ddg", "bitbucket", "bb", "startpage", - "sp"), rlang = TRUE) +search_site(query, site = c("google", "bing", "duckduckgo", "ddg", + "startpage", "sp", "stackoverflow", "so", "rstudio community", "rscom", + "github", "gh", "bitbucket", "bb"), rlang = TRUE) search_google(query = geterrmessage(), rlang = TRUE) @@ -39,6 +41,10 @@ search_stackoverflow(query = geterrmessage(), rlang = TRUE) search_so(query = geterrmessage(), rlang = TRUE) +search_rstudio_community(query = geterrmessage(), rlang = TRUE) + +search_rscom(query = geterrmessage(), rlang = TRUE) + search_github(query = geterrmessage(), rlang = TRUE) search_gh(query = geterrmessage(), rlang = TRUE) @@ -52,7 +58,8 @@ search_bb(query = geterrmessage(), rlang = TRUE) \item{site}{Name of site to search on. Supported options: \code{"google"} (default), \code{"bing"}, \code{"duckduckgo"}, \code{"startpage"}, -\code{"stackoverflow"}, \code{"github"}, and \code{"bitbucket"}.} +\code{"stackoverflow"}, \code{"rstudio community"}, \code{"github"}, and +\code{"bitbucket"}.} \item{rlang}{Search for results written in R. Default is \code{TRUE}} } @@ -106,6 +113,17 @@ search interface please see: \url{https://stackoverflow.com/help/advanced-search-parameters-jobs} } +\section{RStudio Community Search}{ + +The \code{search_rstudio_community()} and \code{search_rscom()} functions both search +\href{https://community.rstudio.com/}{RStudio Community} using: +\code{https://community.rstudio.com/search?q=} + +For additional details regarding \href{https://community.rstudio.com/}{RStudio Community}'s +search interface please see the \href{https://discourse.org}{Discourse} API documentation: +\url{https://docs.discourse.org/#tag/Search} +} + \section{GitHub Search}{ The \code{search_github()} and \code{search_gh()} functions both search @@ -151,6 +169,9 @@ search_stackoverflow("convolutions") # Search all languages on StackOverflow for convolutions search_stackoverflow("convolutions", rlang = FALSE) +# Search RStudio Community +search_rstudio_community("RStudio IDE") + # Search GitHub Issues for bivariate normal in the language:r search_github("bivariate normal") @@ -168,6 +189,6 @@ options(error = search_google) } \seealso{ \code{\link[=search_google]{search_google()}}, \code{\link[=search_bing]{search_bing()}}, \code{\link[=search_duckduckgo]{search_duckduckgo()}}, -\code{\link[=search_startpage]{search_startpage()}}, \code{\link[=search_stackoverflow]{search_stackoverflow()}}, \code{\link[=search_github]{search_github()}}, -\code{\link[=search_bitbucket]{search_bitbucket()}}, \code{\link[=searcher]{searcher()}} +\code{\link[=search_startpage]{search_startpage()}}, \code{\link[=search_stackoverflow]{search_stackoverflow()}}, \code{\link[=search_rstudio_community]{search_rstudio_community()}}, +\code{\link[=search_github]{search_github()}}, \code{\link[=search_bitbucket]{search_bitbucket()}}, and \code{\link[=searcher]{searcher()}} } diff --git a/man/searcher-package.Rd b/man/searcher-package.Rd index 4295391..cdc5bdd 100644 --- a/man/searcher-package.Rd +++ b/man/searcher-package.Rd @@ -7,9 +7,9 @@ \title{searcher: Query Search Interfaces} \description{ Provides a search interface to look up terms - on 'Google', 'Bing', 'DuckDuckGo', 'Startpage', 'StackOverflow', 'GitHub', - and 'BitBucket'. Upon searching, a browser window will open with the - aforementioned search results. + on 'Google', 'Bing', 'DuckDuckGo', 'Startpage', 'StackOverflow', + 'RStudio Community', 'GitHub', and 'BitBucket'. Upon searching, a browser + window will open with the aforementioned search results. } \details{ Provides an interface to search engines via R. @@ -17,8 +17,8 @@ Provides an interface to search engines via R. \seealso{ Useful links: \itemize{ - \item \url{https://github.com/coatless/searcher} - \item Report bugs at \url{https://github.com/coatless/searcher/issues} + \item \url{https://github.com/r-assist/searcher} + \item Report bugs at \url{https://github.com/r-assist/searcher/issues} } } diff --git a/man/searcher.Rd b/man/searcher.Rd index 41965ac..0d01d03 100644 --- a/man/searcher.Rd +++ b/man/searcher.Rd @@ -4,14 +4,15 @@ \alias{searcher} \title{Generate a Searcher function for use with Error Handling} \usage{ -searcher(site = c("google", "bing", "ddg", "sp", "so", "gh", "bb", - "duckduckgo", "stackoverflow", "github", "bitbucket", "startpage"), - rlang = TRUE) +searcher(site = c("google", "bing", "duckduckgo", "ddg", "startpage", + "sp", "stackoverflow", "so", "rstudio community", "rscom", "github", + "gh", "bitbucket", "bb"), rlang = TRUE) } \arguments{ \item{site}{Name of site to search on. Supported options: \code{"google"} (default), \code{"bing"}, \code{"duckduckgo"}, \code{"startpage"}, -\code{"stackoverflow"}, \code{"github"}, and \code{"bitbucket"}.} +\code{"stackoverflow"}, \code{"rstudio community"}, \code{"github"}, and +\code{"bitbucket"}.} \item{rlang}{Search for results written in R. Default is \code{TRUE}} } diff --git a/tests/testthat/test-searcher.R b/tests/testthat/test-searcher.R index ed90b5b..573499e 100644 --- a/tests/testthat/test-searcher.R +++ b/tests/testthat/test-searcher.R @@ -62,6 +62,18 @@ test_that("Check link generation", { "https://stackoverflow.com/search?q=toad" ) + ##### RStudio Community + + expect_identical( + search_rscom("toad"), + "https://community.rstudio.com/search?q=toad" + ) + + expect_identical( + search_rscom("toad", rlang = FALSE), + "https://community.rstudio.com/search?q=toad" + ) + ##### GitHub expect_identical( @@ -161,7 +173,7 @@ test_that("Malformed search query validation", { ) expect_identical( - search_startpage(""), + search_sp(""), "", "Empty string check if no error messages" ) @@ -172,6 +184,13 @@ test_that("Malformed search query validation", { "Empty string check if no error messages" ) + + expect_identical( + search_rscom(""), + "", + "Empty string check if no error messages" + ) + expect_identical( search_gh(""), "",