R lidR save clip_roi object to a LAS file

lidrr

I am trying to save a clip_roi object to a LAS file and I used the code in the following question. However I still get the same error:

Error: Argument is not a LAS object

How can I save a clip_roi object to a LAS file?

lidR: Save LAS files from a clip_roi list

Code:

for (i in range(lengths(clip_roi_object))) 
{
  writeLAS(clip_roi_object[[i]], "path/filename.las", index = FALSE)
}

Best Answer

The question your are linking contains several flaws. Copying the question was not the good idea, you should have copied the answer even if it is a little out-dated by the fact that we prefer to use sf nowadays. Something like that

library(lidR)
library(sf)
ctg <- readLAScatalog(...)
polys <- st_read("shapefile.shp")
opt_output_files(ctg) <- "folder/plot_{ID}"
new_ctg <- clip_roi(ctg, polys)
Related Question