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

4
#' AttributeSpace: An S4 class to represent an attribute space.
5
#'
6
#' This class is used to store planning unit points and demand points for a
7
#' single species in an attribute space.
8
#'
9
#' @slot planning.unit.points [PlanningUnitPoints()] for planning
10
#'   unit in the space.
11
#'
12
#' @slot demand.points [DemandPoints()] object for the space.
13
#'
14
#' @slot species `integer` species id to indicate which species the space
15
#'   is associated with.
16
#'
17
#' @seealso [DemandPoints-class],
18
#'   [PlanningUnitPoints-class].
19
#'
20
#' @name AttributeSpace-class
21
#'
22
#' @rdname AttributeSpace-class
23
#'
24
#' @exportClass AttributeSpace
25
methods::setClass("AttributeSpace",
26
  methods::representation(planning.unit.points = "PlanningUnitPoints",
27
                 demand.points = "DemandPoints",
28
                 species = "integer"),
29
  validity = function(object) {
30
    assertthat::assert_that(isTRUE(ncol(object@demand.points@coords) ==
31
                                   ncol(object@planning.unit.points@coords)),
32
                                   msg = paste0("argument to pu must have ",
33
                                                "same dimensionality as ",
34
                                                "argument to demand.points"))
35
    assertthat::assert_that(all(is.finite(object@species)),
36
                            msg = paste0("argument to species contains NA ",
37
                                         "or non-finite value"))
38
    assertthat::assert_that(assertthat::is.scalar(object@species),
39
                            msg = paste0("argument to species must contain a ",
40
                                         "single integer"))
41
    return(TRUE)
42
  }
43
)
44

45
#' Create new AttributeSpace object
46
#'
47
#' This function creates a new `AttributeSpace` object.
48
#'
49
#' @param planning.unit.points [PlanningUnitPoints()] for planning
50
#'   unit in the space.
51
#'
52
#' @param demand.points [DemandPoints()] object for the space.
53
#'
54
#' @param species `integer` species id to indicate which species the space
55
#'   is associated with.
56
#'
57
#' @seealso [DemandPoints-class],
58
#'   [PlanningUnitPoints-class].
59
#'
60
#' @examples
61
#' space <- AttributeSpace(
62
#'  PlanningUnitPoints(
63
#'    matrix(rnorm(100), ncol = 2),
64
#'    seq_len(50)),
65
#'  DemandPoints(
66
#'    matrix(rnorm(100), ncol = 2),
67
#'    runif(50)),
68
#'  species = 1L)
69
#'
70
#' @export
71
AttributeSpace <- function(planning.unit.points, demand.points, species) {
72 4
  asp <- methods::new("AttributeSpace",
73 4
                      planning.unit.points = planning.unit.points,
74 4
                      demand.points = demand.points, species = species)
75 4
  methods::validObject(asp, test = FALSE)
76 4
  return(asp)
77
}
78

79
#' @method print AttributeSpace
80
#'
81
#' @rdname print
82
#'
83
#' @export
84
print.AttributeSpace <- function(x, ..., header = TRUE) {
85 4
  assertthat::assert_that(assertthat::is.flag(header))
86 4
  if (header)
87 4
    message("AttributeSpace object.")
88 4
  message(ifelse(header, "  ", "    "), "Species: ", x@species)
89 4
  message(ifelse(header, "  ", "      "),
90 4
          "Number of planning unit points: ",
91 4
          nrow(x@planning.unit.points@coords))
92 4
  message(ifelse(header, "  ", "      "),
93 4
          "Number of demand points: ",
94 4
          nrow(x@demand.points@coords))
95 4
  return(invisible())
96
}

Read our documentation on viewing source code .

Loading