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

FR: Don't error ppp when all coordinates are NA #44

Closed
MichaelChirico opened this issue Feb 15, 2017 · 5 comments
Closed

FR: Don't error ppp when all coordinates are NA #44

MichaelChirico opened this issue Feb 15, 2017 · 5 comments

Comments

@MichaelChirico
Copy link
Contributor

MichaelChirico commented Feb 15, 2017

I've got a situation where I'd like to feed all-NA coordinates to ppp (I have a loop where some subsets may be "empty" in the sense of not having any data).

The following works just as expected and accomplishes all I want (I later pixellate this and get the 0s out that I want)

ppp(xrange = 0:1, yrange = 0:1)

But this is an error:

ppp(x = NA_real_, y = NA_real_, xrange = 0:1, yrange = 0:1)

Error in ppp(x = NA_real_, y = NA_real_, xrange = 0:1, yrange = 0:1) :
all coordinate values are NA or NaN

I don't see a reason for the latter to error given the former works just fine (at worst, throw a warning).

Now, I need to throw a test into my code a la:

pixellate(if (all(is.na(xrange))) ppp(xrange = ...) else ppp(x = ....))

Which is considerably more dense/verbose/inscrutable

@rubak
Copy link
Contributor

rubak commented Feb 16, 2017

At the moment ppp doesn't allow any NA vaules. Can't you just filter out the NA values in your call to ppp?

x <- c(NA_real_, NA_real_)
y <- c(NA_real_, NA_real_)
ppp(na.omit(x), na.omit(y), xrange = 0:1, yrange = 0:1)

@baddstats
Copy link
Contributor

I don't see a reason for the latter to error given the former works just fine

The two situations are completely different. NA is not the same as c() or numeric(0). In ppp(xrange, yrange) the coordinate vectors x and y have not been specified, so they default to numeric(0) yielding an empty point pattern. In ppp(NA, NA, xrange, yrange) the coordinates have been specified as a vector of length 1 containing NA. This is an error because ppp objects must not contain NA coordinate values (or a whole lot of code will break).

However, we could tweak ppp so that NA coordinate values are removed with a warning. I will discuss with the three amigos.

@MichaelChirico
Copy link
Contributor Author

@baddstats thanks for the reply.

I understand the two are different -- this may be a case of a misleading error message, then.

See the edit -- the error I receive doesn't imply ppp can't handle missing values, but rather that the problem is there are no non-missing values. So in fact the error message is suggesting the source of the problem is exactly a numeric(0) issue.

Now I see that passing numeric(0) is not an error; thanks for correcting my understanding.

@baddstats
Copy link
Contributor

Experimental code now inserted in ppp (in spatstat 1.49-0.004)

@baddstats
Copy link
Contributor

For the record, ppp does not allow any coordinate values to be NA, NaN or infinite.
I will re-write the error message and the help file to make this abundantly clear.

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

3 participants