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

extract: helper/checker for length-2 atomic vector input #1757

Closed
mdsumner opened this issue Mar 4, 2025 · 2 comments
Closed

extract: helper/checker for length-2 atomic vector input #1757

mdsumner opened this issue Mar 4, 2025 · 2 comments

Comments

@mdsumner
Copy link
Contributor

mdsumner commented Mar 4, 2025

A very common error I have made in the past is to input a point for extract and expect a value for a single point:

library(terra)
r <- rast(matrix(1:12, 3, 4))
extract(r, c(2.3, 1.1))

It's a very specific case, input of length==2, numeric input, but I think it's worthy of a message to warn potential mistaken input - especially if either value is outside (1, ncell) or has fractional component. Happy to PR just wanted to record the idea, after a colleague asked me about it, they'd been trying to figure it out for a while.

@mdsumner mdsumner changed the title extract: helper/checker for atomic vector input extract: helper/checker for length-2 atomic vector input Mar 4, 2025
rhijmans added a commit that referenced this issue Mar 4, 2025
@rhijmans
Copy link
Member

rhijmans commented Mar 4, 2025

Yes, that is one of these things where R can easily trip you. I have added a check and warning.

@mdsumner
Copy link
Contributor Author

mdsumner commented Mar 4, 2025

awesome thank you, just should also check for NA/Inf lest the dreaded "missing value where TRUE/FALSE" needed (I'll also do some more checks)

rhijmans added a commit that referenced this issue Mar 4, 2025
@rhijmans rhijmans closed this as completed Mar 5, 2025
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

2 participants