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

> ### Name: catalog_apply
> ### Title: LAScatalog processing engine
> ### Aliases: catalog_apply catalog_sapply
> 
> ### ** Examples
> 
> # More examples might be avaible in the official lidR vignettes or
> # on the github wiki <http://jean-romain.github.io/lidR/wiki>
> 
> ## =========================================================================
> ## Example 1: detect all the tree tops over an entire catalog
> ## (this is basically a reproduction of the existing lidR function 'tree_detection')
> ## =========================================================================
> 
> # 1. Build the user-defined function that analyzes each chunk of the catalog.
> # The function's first argument is a LAScluster object. The other arguments can be freely
> # choosen by the user.
> my_tree_detection_method <- function(cluster, ws)
+ {
+   # The cluster argument is a LAScluster object. The user does not need to know how it works.
+   # readLAS will load the region of interest (chunk) with a buffer around it, taking advantage of
+   # point cloud indexation if possible. The filter and select options are propagated automatically
+   las <- readLAS(cluster)
+   if (is.empty(las)) return(NULL)
+ 
+   # Find the tree tops using a user-developed method (here simply a LMF).
+   ttops <- tree_detection(las, lmf(ws))
+ 
+   # ttops is a SpatialPointsDataFrame that contains the tree tops in our region of interest
+   # plus the trees tops in the buffered area. We need to remove the buffer otherwise we will get
+   # some trees more than once.
+   bbox  <- raster::extent(cluster)
+   ttops <- raster::crop(ttops, bbox)
+ 
+   return(ttops)
+ }
> 
> # 2. Build a project (here, a single file catalog for the purposes of this dummmy example).
> LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
> project <- readLAScatalog(LASfile)
Warning: multiple methods tables found for 'plot'
> plot(project)
> 
> # 3. Set some catalog options.
> # For this dummy example, the chunk size is 80 m and the buffer is 10 m
> opt_chunk_buffer(project) <- 10
> opt_chunk_size(project)   <- 80            # small because this is a dummy example.
Be careful, a chunk size smaller than 250 is likely to be irrelevant.
> opt_select(project)       <- "xyz"         # read only the coordinates.
> opt_filter(project)       <- "-keep_first" # read only first returns.
> 
> # 4. Apply a user-defined function to take advantage of the internal engine
> opt    <- list(need_buffer = TRUE,   # catalog_apply will throw an error if buffer = 0
+                automerge   = TRUE)   # catalog_apply will merge the outputs into a single object
> output <- catalog_apply(project, my_tree_detection_method, ws = 5, .options = opt)
Chunk 1 of 4 (25%): state <U+2713>
Chunk 2 of 4 (50%): state <U+2713>
Chunk 3 of 4 (75%): state <U+2713>
Chunk 4 of 4 (100%): state <U+2713>
> 
> spplot(output)
> 
> ## ===================================================
> ## Example 2: compute a rumple index on surface points
> ## ===================================================
> 
> rumple_index_surface = function(cluster, res)
+ {
+   las = readLAS(cluster)
+   if (is.empty(las)) return(NULL)
+ 
+   las    <- lasfiltersurfacepoints(las, 1)
+   rumple <- grid_metrics(las, ~rumple_index(X,Y,Z), res)
+   bbox   <- raster::extent(cluster)
+   rumple <- raster::crop(rumple, bbox)
+ 
+   return(rumple)
+ }
> 
> LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
> project <- readLAScatalog(LASfile)
> 
> opt_chunk_buffer(project) <- 1
> opt_chunk_size(project)   <- 120     # small because this is a dummy example.
Be careful, a chunk size smaller than 250 is likely to be irrelevant.
> opt_select(project)       <- "xyz"   # read only the coordinates.
> 
> opt     <- list(raster_alignment = 20, # catalog_apply will adjust the chunks if required
+                 automerge = TRUE)      # catalog_apply will merge the outputs into a single raster
> output  <- catalog_apply(project, rumple_index_surface, res = 20, .options = opt)
Chunk 1 of 9 (11.1%): state <U+2713>
Chunk 2 of 9 (22.2%): state <U+2713>
Chunk 3 of 9 (33.3%): state <U+2713>
Chunk 4 of 9 (44.4%): state <U+2713>
Chunk 5 of 9 (55.6%): state <U+2713>
Chunk 6 of 9 (66.7%): state <U+2713>
Chunk 7 of 9 (77.8%): state <U+2713>
Chunk 8 of 9 (88.9%): state <U+2713>
Chunk 9 of 9 (100%): state <U+2713>
> 
> plot(output, col = height.colors(50))
Error in as.double(y) : 
  cannot coerce type 'S4' to vector of type 'double'
Calls: plot -> plot -> plot.default -> xy.coords
Execution halted