diff --git a/.Rbuildignore b/.Rbuildignore index c503c4f..d325fbf 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1 +1,3 @@ ^\.github$ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/NASCENT-Peru.Rproj b/NASCENT-Peru.Rproj index 1ff30a8..dead601 100644 --- a/NASCENT-Peru.Rproj +++ b/NASCENT-Peru.Rproj @@ -11,3 +11,7 @@ Encoding: UTF-8 RnwWeave: Sweave LaTeX: XeLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/src/scripts/preparation/test_rast_save_options.R b/src/scripts/preparation/test_rast_save_options.R new file mode 100644 index 0000000..0415556 --- /dev/null +++ b/src/scripts/preparation/test_rast_save_options.R @@ -0,0 +1,56 @@ +install.packages("terra") +library(terra) + +#load test rast +test_rast <- terra::rast("X:/NASCENT-Peru/03_workspaces/02_modelling/Data_collab/Preds/Prepared/Suitability/Biophysical/Bulk_density/bdod_5-15cm_mean.tif") + +#check min/max values +minmax(test_rast) + +#test if rats is integer +is.int(test_rast) + +### ========================================================================= +### Convert to integer +### ========================================================================= + +#multiple by 1000 to convert to integer +test_rast_int <- test_rast * 10000 + +#check min/max values +minmax(test_rast_int) + +#test if rats is integer +is.int(test_rast_int) + +### ========================================================================= +### Check size using Geotiff +### ========================================================================= + +#save using INT2U datatype +writeRaster(test_rast, + datatype= "INT2U", + filename = "X:/NASCENT-Peru/03_workspaces/02_modelling/Data_collab/Preds/Prepared/Suitability/Biophysical/Bulk_density/test_int_rast.tif") + + +#re-read +test_int2U <- rast("X:/NASCENT-Peru/03_workspaces/02_modelling/Data_collab/Preds/Prepared/Suitability/Biophysical/Bulk_density/test_int_rast.tif") +is.int(test_int2U) + +#attempt to force rast values into memory +test_rds <- test_int2U *1 + +### ========================================================================= +### Check size using RDS +### ========================================================================= + +# Convert back to raster as terra::saveRDS only saves reference +test_rds <- raster::raster(test_int2U) + +# Use raster::readall to ensure values are in memory +# THIS FAILS BECAUSE OF RAM LIMITS +test_rds <- raster::readAll(test_rds) + +#save as RDS instead +terra::saveRDS(test_rds, "X:/NASCENT-Peru/03_workspaces/02_modelling/Data_collab/Preds/Prepared/Suitability/Biophysical/Bulk_density/test_rast.rds") +