ohagen / gen3sis_rf

Repository of the R-packageGen3sis
https://project-gen3sis.github.io/R-package/
GNU General Public License v3.0
1 stars 0 forks source link

`make_summary()` throws an error with h3 spaces #2

Open castroinsua opened 4 months ago

castroinsua commented 4 months ago

As @ohagen reported in an email, make_summary() will throw an error when running simulations with spaces of type gen3sis_space_h3:

Error in final_richness[as.integer(names(richness)), ncol(final_richness)] <- richness : 
  NAs are not allowed in subscripted assignments
In addition: Warning message:
In make_summary(val$config, val$data, val$vars, total_runtime, save_file = TRUE) :
  NAs introduced by coercion

The reason for this is that the site names in simulations with h3 spaces are not numbers as it was the case with rasters, but strings like "8003fffffffffff", which cannot be converted to integers with the as.integer function. I did not have time to have a proper look at this, but I think that the final_richness matrix in this function has row names, so it should not be necessary to use as.integer to select rows. However, right now I am not sure if it is always guaranteed to have row names.

castroinsua commented 4 months ago

There is also a very similar problem in disperse_species(). It tries to convert the site names to numbers to sort them here:

  sorted <- as.character(sort(as.numeric(names(index))))

I am not familiar with this part of the code so I am not sure why they need to be sorted, but these calls to as.numeric() have to be avoided somehow when working with h3.