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

> ### Name: aggregate
> ### Title: Metric derivation at different levels of regularization
> ### Aliases: aggregate cloud_metrics crown_metrics hexagon_metrics
> ###   pixel_metrics plot_metrics polygon_metrics template_metrics
> ###   voxel_metrics
> 
> ### ** Examples
> 
> LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
> las <- readLAS(LASfile, filter = "-keep_random_fraction 0.5")
> col <- sf::sf.colors(15)
> fun1 <- ~list(maxz = max(Z))
> fun2 <- ~list(q85 = quantile(Z, probs = 0.85))
> 
> # ================
> # TEMPLATE METRICS
> # ================
> 
> # a raster as template
> template <- raster::raster(extent(las), nrow = 15, ncol = 15)
> raster::crs(template) <- crs(las)
> m <- template_metrics(las, fun1, template)
> plot(m, col = col)
> 
> # a sfc_POLYGON as template
> sfc <- sf::st_as_sfc(st_bbox(las))
> template <- sf::st_make_grid(sfc, cellsize = 20, square = FALSE)
> m <- template_metrics(las, fun1, template)
> plot(m)
> 
> # a bbox as template
> template <- st_bbox(las) + c(50,30,-50,-70)
> plot(sf::st_as_sfc(st_bbox(las)), col = "gray")
> plot(sf::st_as_sfc(template), col = "darkgreen", add = TRUE)
> m <- template_metrics(las, fun2, template)
> print(m)
$q85
[1] 21.52

> 
> # ================
> # CUSTOM METRICS
> # ================
> 
> # Define a function that computes custom metrics
> # in an R&D perspective.
> myMetrics = function(z, i) {
+   metrics = list(
+      zwimean = sum(z*i)/sum(i), # Mean elevation weighted by intensities
+      zimean  = mean(z*i),       # Mean products of z by intensity
+      zsqmean = sqrt(mean(z^2))) # Quadratic mean
+ 
+    return(metrics)
+ }
> 
> # example with a stars template
> template <- stars::st_as_stars(st_bbox(las), dx = 10, dy = 10)
> m <- template_metrics(las, ~myMetrics(Z, Intensity), template)
> plot(m, col = col)
> 
> # ================
> # CLOUD METRICS
> # ================
> 
> cloud_metrics(las, .stdmetrics_z)
$zmax
[1] 29.11

$zmean
[1] 13.27629

$zsd
[1] 7.456352

$zskew
[1] -0.4764641

$zkurt
[1] 2.086569

$zentropy
[1] 0.9034754

$pzabovezmean
[1] 57.36855

$pzabove2
[1] 85.71007

$zq5
[1] 0

$zq10
[1] 0.09

$zq15
[1] 2.86

$zq20
[1] 5.79

$zq25
[1] 7.81

$zq30
[1] 9.64

$zq35
[1] 11.21

$zq40
[1] 12.63

$zq45
[1] 13.83

$zq50
[1] 14.91

$zq55
[1] 16

$zq60
[1] 16.89

$zq65
[1] 17.71

$zq70
[1] 18.53

$zq75
[1] 19.3

$zq80
[1] 20.09

$zq85
[1] 20.88

$zq90
[1] 21.79

$zq95
[1] 23.05

$zpcum1
[1] 6.52697

$zpcum2
[1] 12.03731

$zpcum3
[1] 20.22982

$zpcum4
[1] 30.04461

$zpcum5
[1] 43.09585

$zpcum6
[1] 59.87833

$zpcum7
[1] 80.14871

$zpcum8
[1] 95.21968

$zpcum9
[1] 99.55928

> 
> # ================
> # PIXEL METRICS
> # ================
> 
> m <- pixel_metrics(las, fun1, 20)
> plot(m, col = col)
> 
> m = pixel_metrics(las, ~myMetrics(Z, Intensity))
Error: 'set.values' is not an exported object from 'namespace:terra'
Execution halted