Running examples in ‘prioritizr-Ex.R’ failed
The error most likely occurred in:

> ### Name: add_linear_penalties
> ### Title: Add linear penalties
> ### Aliases: add_linear_penalties
> ###   add_linear_penalties,ConservationProblem,ANY,Matrix-method
> ###   add_linear_penalties,ConservationProblem,ANY,matrix-method
> ###   add_linear_penalties,ConservationProblem,ANY,dgCMatrix-method
> ###   add_linear_penalties,ConservationProblem,ANY,character-method
> ###   add_linear_penalties,ConservationProblem,ANY,numeric-method
> ###   add_linear_penalties,ConservationProblem,ANY,Raster-method
> 
> ### ** Examples
> 
> # set seed for reproducibility
> set.seed(600)
> 
> # load data
> data(sim_pu_polygons, sim_pu_zones_stack, sim_features, sim_features_zones)
> 
> # add a column to contain the penalty data for each planning unit
> # e.g. these values could indicate the level of habitat
> sim_pu_polygons$penalty_data <- runif(nrow(sim_pu_polygons))
> 
> # plot the penalty data to visualise its spatial distribution
> spplot(sim_pu_polygons, zcol = "penalty_data", main = "penalty data",
+        axes = FALSE, box = FALSE)
> 
> # create minimal problem with minimum set objective,
> # this does not use the penalty data
> p1 <- problem(sim_pu_polygons, sim_features, cost_column = "cost") %>%
+       add_min_set_objective() %>%
+       add_relative_targets(0.1) %>%
+       add_binary_decisions() %>%
+       add_default_solver(verbose = FALSE)
> 
> # print problem
> print(p1)
Conservation Problem
  planning units: SpatialPolygonsDataFrame (90 units)
  cost:           min: 190.13276, max: 215.86384
  features:       layer.1, layer.2, layer.3, ... (5 features)
  objective:      Minimum set objective 
  targets:        Relative targets [targets (min: 0.1, max: 0.1)]
  decisions:      Binary decision 
  constraints:    <none>
  penalties:      <none>
  portfolio:      default
  solver:         MissingSolver []
> 
> # create an updated version of the previous problem,
> # with the penalties added to it
> p2 <- p1 %>% add_linear_penalties(100, data = "penalty_data")
> 
> # print problem
> print(p2)
Conservation Problem
  planning units: SpatialPolygonsDataFrame (90 units)
  cost:           min: 190.13276, max: 215.86384
  features:       layer.1, layer.2, layer.3, ... (5 features)
  objective:      Minimum set objective 
  targets:        Relative targets [targets (min: 0.1, max: 0.1)]
  decisions:      Binary decision 
  constraints:    <none>
  penalties:      <Linear penalties [penalty (100)]>
  portfolio:      default
  solver:         MissingSolver []
> 
> ## Not run: 
> ##D # solve the two problems
> ##D s1 <- solve(p1)
> ##D s2 <- solve(p2)
> ##D 
> ##D # plot the solutions and compare them,
> ##D # since we supplied a very high penalty value (i.e. 100), relative
> ##D # to the range of values in the penalty data and the objective function,
> ##D # the solution in s2 is very sensitive to values in the penalty data
> ##D spplot(s1, zcol = "solution_1", main = "solution without penalties",
> ##D        axes = FALSE, box = FALSE)
> ##D spplot(s2, zcol = "solution_1", main = "solution with penalties",
> ##D        axes = FALSE, box = FALSE)
> ##D 
> ##D # for real conservation planning exercises,
> ##D # it would be worth exploring a range of penalty values (e.g. ranging
> ##D # from 1 to 100 increments of 5) to explore the trade-offs
> ## End(Not run)
> 
> # now, let's examine a conservation planning exercise involving multiple
> # management zones
> 
> # create targets for each feature within each zone,
> # these targets indicate that each zone needs to represent 10% of the
> # spatial distribution of each feature
> targ <- matrix(0.1, ncol = number_of_zones(sim_features_zones),
+                nrow = number_of_features(sim_features_zones))
> 
> # create penalty data for allocating each planning unit to each zone,
> # these data will be generated by simulating values
> penalty_stack <- simulate_cost(sim_pu_zones_stack[[1]],
+                                n = number_of_zones(sim_features_zones))
Error in simulate_data(x, n = n, model = model, transform = transform,  : 
  the "RandomFields" package needs to be installed to simulate data
Calls: simulate_cost -> simulate_data
Execution halted