-
Notifications
You must be signed in to change notification settings - Fork 89
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
SpatRaster breaks when saved as an R object #549
Comments
This is not an issue. In the package description, at the very beginning it says: |
Thank you for pointing out the relevant part of the documentation. I missed the paragraph you referred me to, and indeed, something along those lines is what I was expecting. Yet I am a bit confused of why you consider it to not be an issue. It is good that Moreover, I see only benefits from mentioning this aspect in parts of the documentation that are more read than the introduction, e.g. Of course, now I am thinking that this could be an issue for CRAN as well, as this could have been checked there, but it would be a completely different issue. |
Thank you for your suggestions. I have now added
So this won't work for SpatRasters that point to a file or files. Further refinement could be to then read all values into memory for smaller SpatRasters.
|
From my point of view, this wasn't a request, but a suggestion that may or may not be implemented some time in the future. Nevertheless, your promptness in tackling this issue is greatly appreciated. Moreover I learned quite a bit from your reply alone.
I understand your feelings about Ultimately, I still think that the documentation for |
The fundamental issue is that Spat* objects are S4 (R) objects that hold a reference object (a C++ object). serialize/saveRDS do not work correctly with reference objects. Your suggestion to overload serialize/saveRDS was very useful. These overloaded functions call Doing this with a raster that points to a file is a different problem. There is no guarantee that the file will exist in the future, let alone on another computer. There are specialized file formats for raster data such as GeoTiff that can, and should be used instead. Or you can just store the filename. Also, right now,
There is an internal method |
Sorry, a bit off-topic but I was wondering about I have a possible use case where exporting readAll would "help": Say you have an R function that provides access to a web coverage service that downloads a tif file to a temporary location for some user-specified extent. After the download is complete, the result is read into memory and the temporary file deleted so the user doesn't have to deal with the temp file/function has no side effects in the file system. To be able to unlink the temporary file, and have the user still be able to use the SpatRaster, values need to be in memory. For my example case there are API constraints on extent and resolution that generally prevent requesting very large results--so it can be "assumed" the result will fit in memory. Any suggestions for this? |
@kadyb Thanks! I recall reading that now. I had done the conversion for the case in question back in December, so about a month before the |
Thanks, I also forgot about |
SpatRaster
objects do not seem to work as regular R objects, when it comes to being saved usingsave
, orsaveRDS
, orserialize
. Moreover no error or warning is produced when savingSpatRaster
R objects. This means that this issue will cause data loss without warning when encountered.The code below can be used to reproduce the issue.
Ideally,
SpatRaster
s would behave like any other R object.If the ideal solution is not preferred, alternatively
serialize
could be overloaded for classSpatRaster
to give a clear error. Moreover, the documentation (?rast
?SpatRaster
?writeRaster
) can be improved to warn users aboutSpatRaster
s limitation.The text was updated successfully, but these errors were encountered: