Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using pixel_metrics() within a function does not work? #781

Open
zoeschindler opened this issue Sep 20, 2024 · 0 comments
Open

Using pixel_metrics() within a function does not work? #781

zoeschindler opened this issue Sep 20, 2024 · 0 comments

Comments

@zoeschindler
Copy link

Hello, I am not sure whether I found a bug, a feature or if I wrote bad code, but I have some code which is not working like I expected. I have an example here:

# load file
las <- readLAS(system.file("extdata", "Megaplot.laz", package="lidR"))

# set options
val <- 3

# get metrics without function
rast <- pixel_metrics(las, length(X) > val, res = 1)
# -> works

# get metrics with function
dummy <- function(las, minimum) {
  rast <- pixel_metrics(las, length(X) > minimum, res = 1)
}
dummy(las = las, minimum = val)
# -> does not work

When I use pixel_metrics inside a function, it does not work. I get an error that the variable "minimum" wasn't found. I get this traceback:

Fehler: Objekt 'minimum' nicht gefunden
10. `[.data.table`(las@data, , if (!anyNA(.BY)) length(X) > minimum, by = .(cells, echo)) at <text>#1
9. las@data[, if (!anyNA(.BY)) length(X) > minimum, by = .(cells, echo)] at <text>#1
8. eval(parse(text = cmd))
7. eval(parse(text = cmd))
6. metrics_classic(las, call, grp, filter)
5. template_metrics.LAS(las, func, template, ...)
4. template_metrics(las, func, template, ...)
3. pixel_metrics.LAS(las, length(X) > minimum, res = 1)
2. pixel_metrics(las, length(X) > minimum, res = 1)
1. dummy(las = las, minimum = val)

I am happy about any help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant