@@ -148,13 +148,16 @@ CRANsearcher <- function(){
148148 if (identical(search_d(), character (0 )) || nchar(search_d())< 2 ){
149149 s <- 0
150150 } else {
151+
151152 s <- a %> %
152153 mutate(term = tolower(paste(name , Title , Description , sep = " ," ))) %> %
153154 rowwise %> %
154155 mutate(match = all(stringr :: str_detect(term , search2 ))) %> %
155156 filter(match == TRUE ) %> %
156157 select(- c(term , match )) %> %
157158 data.frame
159+
160+ if (nrow(s ) == 0 ) s <- 0
158161 }
159162 return (s )
160163 })
@@ -189,6 +192,9 @@ CRANsearcher <- function(){
189192 return ()
190193 }
191194 } else {
195+ validate(
196+ need(a_sub2() != 0 , " Your search returned no results. Please try again." )
197+ )
192198 DT :: datatable(a_sub2()[,c(1 : 6 )],
193199 rownames = FALSE ,
194200 escape = FALSE ,
@@ -205,6 +211,12 @@ CRANsearcher <- function(){
205211
206212 note <- ifelse(! is.null(crandb $ snapshot_date ), paste0(" (as of " , crandb $ snapshot_date ," )" , " " ))
207213
214+ if (length(search_d())< = 1 ){
215+ pkg <- search_d()
216+ } else {
217+ pkg <- paste(search_d(), collapse = " , " )
218+ }
219+
208220 if (identical(search_d(), character (0 )) || nchar(search_d())< 2 ){
209221 if (! is.null(crandb $ a )){
210222
@@ -217,19 +229,20 @@ CRANsearcher <- function(){
217229 paste(" " )
218230 }
219231 } else {
232+ req(a_sub2() != 0 )
220233 n <- dim(a_sub2())[1 ]
221234
222235 if (! n == 1 ){
223236 if (input $ dates == " All time" ){
224- paste0(" There are " ,n ," packages related to '" ,search_d() ," ' on CRAN" , note ," ." )
237+ paste0(" There are " ,n ," packages related to '" ,pkg ," ' on CRAN" , note ," ." )
225238 } else {
226- paste0(" There are " ,n ," packages related to '" ,search_d() ," ' on CRAN released within the past " ,input $ dates ,note ," ." )
239+ paste0(" There are " ,n ," packages related to '" ,pkg ," ' on CRAN released within the past " ,input $ dates ,note ," ." )
227240 }
228241 } else {
229242 if (input $ dates == " All time" ){
230- paste0(" There is " ,n ," package related to '" ,search_d() ," ' on CRAN" , note , " ." )
243+ paste0(" There is " ,n ," package related to '" ,pkg ," ' on CRAN" , note , " ." )
231244 } else {
232- paste0(" There is " ,n ," package related to '" ,search_d() ," ' on CRAN released within the past " ,input $ dates ,note ," ." )
245+ paste0(" There is " ,n ," package related to '" ,pkg ," ' on CRAN released within the past " ,input $ dates ,note ," ." )
233246 }
234247 }
235248 }
0 commit comments