1
#' @include RcppExports.R raptr-internal.R generics.R misc.R
2
NULL
3

4
#' PlanningUnitPoints: An S4 class to represent planning units in an attribute
5
#' space
6
#'
7
#' This class is used to planning units in an attribute space.
8
#'
9
#' @slot coords [base::matrix()] coordinates for each point.
10
#'
11
#' @slot ids `integer` planning unit ids.
12
#'
13
#' @seealso [AttributeSpace()].
14
#'
15
#' @name PlanningUnitPoints-class
16
#'
17
#' @rdname PlanningUnitPoints-class
18
#'
19
#' @exportClass PlanningUnitPoints
20
methods::setClass("PlanningUnitPoints",
21
  methods::representation(coords = "matrix", ids = "integer"),
22
  validity = function(object) {
23
    # coords
24
    assertthat::assert_that(all(is.finite(object@coords)),
25
                            msg = paste0("argument to coords contains NA or ",
26
                                         "non-finite values"))
27
    assertthat::assert_that(nrow(object@coords) > 0,
28
                            msg = paste0("argument to coords must contain at ",
29
                                         "least one row"))
30
    # ids
31
    assertthat::assert_that(all(is.finite(object@ids)),
32
                            msg = paste0("argument to ids contains NA of ",
33
                                         "non-finite values"))
34
    assertthat::assert_that(length(object@ids) > 0,
35
                            msg = paste0("argument to ids must contain at ",
36
                                         "least one element"))
37
    # cross checks
38
    assertthat::assert_that(length(object@ids) == nrow(object@coords),
39
                            msg = paste0("length of ids is not equal to ",
40
                                         "number of rows in coordinates"))
41
    return(TRUE)
42
  }
43
)
44

45
#' Create new PlanningUnitPoints object
46
#'
47
#' This function creates a new `PlanningUnitPoints` object.
48
#'
49
#' @param coords [base::matrix()] coordinates for each point.
50
#'
51
#' @param ids `integer` planning unit ids.
52
#'
53
#' @seealso [AttributeSpace-class].
54
#'
55
#' @examples
56
#' # create PlanningUnitPoints object
57
#' x <- PlanningUnitPoints(matrix(rnorm(150), ncol = 1), seq_len(150))
58
#'
59
#' # print object
60
#' print(x)
61
#'
62
#' @export
63
PlanningUnitPoints <- function(coords, ids) {
64 4
  sp <- methods::new("PlanningUnitPoints", coords = coords, ids = ids)
65 4
  methods::validObject(sp, test = FALSE)
66 4
  return(sp)
67
}

Read our documentation on viewing source code .

Loading