/
as-ypr-populations.R
66 lines (58 loc) · 1.5 KB
/
as-ypr-populations.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#' Coerce to a Populations Object
#'
#' @param x The object to coerce.
#' @param ... Unused.
#' @return An object of class ypr_ecotypes.
#' @family populations
#' @export
as_ypr_populations <- function(x, ...) {
UseMethod("as_ypr_populations")
}
#' @describeIn as_ypr_population Coerce a data.frame to a Populations Object
#'
#' @export
#' @examples
#' as_ypr_populations(as.data.frame(ypr_populations(Rk = c(3, 4))))
as_ypr_populations.data.frame <- function(x, ...) {
chk_data(x)
chk_unused(...)
x <- split(x, seq_len(nrow(x)))
x <- lapply(x, as_ypr_population)
class(x) <- "ypr_populations"
names(x) <- ypr_names(x)
x
}
#' @describeIn as_ypr_populations Coerce a Population Object to an Population Object
#'
#' @export
#' @examples
#' as_ypr_populations(ypr_population())
as_ypr_populations.ypr_population <- function(x, ...) {
check_population(x)
chk_unused(...)
x <- list(x)
class(x) <- "ypr_populations"
names(x) <- ypr_names(x)
x
}
#' @describeIn as_ypr_populations Coerce a Populations Object of length 1 to a Population Object
#'
#' @export
#' @examples
#' as_ypr_populations(ypr_populations())
as_ypr_populations.ypr_populations <- function(x, ...) {
check_populations(x)
chk_unused(...)
x
}
#' @describeIn as_ypr_populations Coerce a Ecotypes Object of length 1 to a Population Object
#'
#' @export
#' @examples
#' as_ypr_populations(ypr_ecotypes())
as_ypr_populations.ypr_ecotypes <- function(x, ...) {
check_ecotypes(x)
chk_unused(...)
class(x) <- "ypr_populations"
x
}