Q:

Creating the delineate_crown function using lidR package in R?

I can't seem to create a delineate_crown() function using the lidR package. I am using the example code given at page 33 of lidR.pdf to get familiar with the function. Furthermore, I tried playing with both tree_hulls() and delineate_crown(), and I don't know what I am doing wrong. When I try to plot (line 15) using the delineate_crown function, I get the this error:
Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,  : 
  'expr' did not evaluate to an object of length 'n'

I have tried to make the example code simple. I am actually using the code on the tree_hulls() source code page (https://rdrr.io/cran/lidR/src/R/tree_hulls.r). As I am not that experienced with R, I can't seem to create the object convex_hulls at line 9 and so I can't plot it. The code is as follows:
#Compute convex hull
library(lidR)
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile, select = "xyz0", filter = "-drop_z_below 0")
# NOTE: This dataset is already segmented
plot(las, colorPalette = pastel.colors(200))
# Only the hulls
tree_hulls = function(las, type = c("convex", "concave", "bbox"), concavity = 3,length_threshold = 0, func = NULL, attribute = "treeID") 
convex_hulls = tree_hulls(las)
plot(convex_hulls) 

A:

I'm still unable to understand what you are trying to do. Your example is the one from the documentation but with some modifications that are not valid R syntax and you are not explaining why you changed something and what are your intentions behind these modifications. The original example from the documentation works well and your example does not throw the error you are mentioning.
library(lidR)
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las = readLAS(LASfile, select = "xyz0", filter = "-drop_z_below 0")

convex_hulls = delineate_crowns(las)
plot(convex_hulls)

Please note that tree_hull() is deprecated from version 3.0.0. It is replaced by delineate_crown() that does the same.

