-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployments.R
38 lines (37 loc) · 1.06 KB
/
deployments.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
#' Get or set deployments
#'
#' @description
#' `deployments()` gets the deployments from a Camera Trap Data Package object.
#'
#' `deployments<-()` is the assignment equivalent.
#' It should only be used within other functions, where the expected data
#' structure can be guaranteed.
#'
#' @inheritParams check_camtrapdp
#' @return [tibble()] data frame with deployments.
#' @family accessor functions
#' @export
#' @examples
#' x <- example_dataset()
#' # Get deployments
#' deployments(x)
#'
#' # Set deployments (not recommended outside a function)
#' deployments(x) <- head(deployments(x), 1)
deployments <- function(x) {
check_camtrapdp(x)
purrr::pluck(x, "data", "deployments")
}
#' @rdname deployments
#' @param value A data frame to assign as deployments.
#' @export
"deployments<-" <- function(x, value) {
if (!is.data.frame(value)) {
cli::cli_abort(
"{.arg value} must be a data.frame, not {.type {value}}.",
class = "camtrapdp_error_assignment_wrong_class"
)
}
purrr::pluck(x, "data", "deployments") <- dplyr::as_tibble(value)
return(x)
}