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

Error in if (prj != "") { : missing value where TRUE/FALSE needed #890

Closed
athammad opened this issue Nov 11, 2022 · 2 comments
Closed

Error in if (prj != "") { : missing value where TRUE/FALSE needed #890

athammad opened this issue Nov 11, 2022 · 2 comments

Comments

@athammad
Copy link

athammad commented Nov 11, 2022

In trying to save a couple of large rasters in one single nc file. I got the following error.

multiRaster<-sds(Mraster)
writeCDF(multiRaster, "./NCfiles/multiRaste.nc",overwrite=TRUE)

Error in if (prj != "") { : missing value where TRUE/FALSE needed

I went to check the crs of the single files but everything looks fine.

Update
It seems the issue is with tapp. Here is a simple way to reproduce the error

r <- rast(ncols=10, nrows=10)
values(r) <- 1:ncell(r)
s <- c(r, r, r, r, r, r)
s <- s * 1:6
b1 <- tapp(s, index=c(1,1,1,2,2,2), fun=mean)
writeCDF(b1, "xxx.nc", overwrite=TRUE)
@kadyb
Copy link
Contributor

kadyb commented Nov 11, 2022

This looks like regression because it works in 1.6.17. Have you tried to set up some CRS?

r <- rast(ncols=10, nrows=10, vals = 0)
writeCDF(r, "xxx.nc", overwrite=TRUE)
#> Error in if (prj != "") { : missing value where TRUE/FALSE needed

r <- rast(ncols=10, nrows=10, vals = 0, crs = "local")
writeCDF(r, "xxx.nc", overwrite=TRUE)
#> Error in if (prj != "") { : missing value where TRUE/FALSE needed

r <- rast(ncols=10, nrows=10, vals = 0, crs = "")
writeCDF(r, "xxx.nc", overwrite=TRUE)
# works

r <- rast(ncols=10, nrows=10, vals = 0, crs = "epsg:4326")
writeCDF(r, "xxx.nc", overwrite=TRUE)
# works

@rhijmans
Copy link
Member

Thanks. This was introduced because of a change that makes writeCDF also write the EPSG code of the crs to the file. This failed for cases when there was no EPSG code; I tested for it be "" where the test should be for NA in this case.

@athammad athammad mentioned this issue Feb 21, 2023
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