-
Notifications
You must be signed in to change notification settings - Fork 62
/
pin_search.R
43 lines (40 loc) · 1.37 KB
/
pin_search.R
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
#' Search for pins
#'
#' The underlying search method depends on the `board`, but most will search
#' for text in the pin name and title.
#'
#' @returns A data frame that summarises the metadata for each pin.
#' Key attributes (`name`, `type`, `description`, `created`, and `file_size`)
#' are pulled out into columns; everything else can be found in the `meta`
#' list-column.
#' @inheritParams pin_read
#' @param search A string to search for in pin name and title.
#' Use `NULL` to return all pins.
#' @param ... Additional arguments passed on to methods.
#' @export
#' @examples
#' board <- board_temp()
#'
#' board %>% pin_write(1:5, "x", title = "Some numbers")
#' board %>% pin_write(letters[c(1, 5, 10, 15, 21)], "y", title = "My favourite letters")
#' board %>% pin_write(runif(20), "z", title = "Random numbers")
#'
#' board %>% pin_search()
#' board %>% pin_search("number")
#' board %>% pin_search("letters")
pin_search <- function(board, search = NULL, ...) {
check_board(board, "pin_search()", "pin_find()")
ellipsis::check_dots_used()
UseMethod("pin_search")
}
#' @export
pin_search.pins_board <- function(board, search = NULL, ...) {
names <- pin_list(board)
out <- multi_meta(board, names)
if (!is.null(search)) {
match <- grepl(search, out$name, fixed = TRUE) |
grepl(search, out$title, fixed = TRUE)
out <- out[match, , drop = FALSE]
}
out
}