Skip to content

Samples_beta_from_plots introduces NaN for empty tiles #43

Description

@simonbonnefoy

The line 74

samples_beta_terra[-as.numeric(names(elimNull))]

in the sample_from_plots_beta.R function introduces NaN if the names of elimNull are strings.
elimNull is a list that contains the name of the plots without data. If the names are of type string, the function as.numeric() will return a NaN.

This breaks the execution with the following error:

initialization of biodivMapR                                                                                                                                                                                                                                                    
biodivMapR sampling                                                                                                                                                                                                                                                             
compute stats                                                                                                                                                                                                                                                                   
get samples for beta diversity                                                                                                                                                                                                                                                  
Erreur dans UseMethod("group_split") :                                                                                                                                                                                                                                          
  pas de méthode pour 'group_split' applicable pour un objet de classe "NULL"                                                                                                                                                                                                   
Appels : biodivMapR_full_tiles ... biodivMapR_sample -> init_PCoA_samples -> %>% -> group_split                                                                                                                                                                                 
De plus : Message d'avis :                                                                                                                                                                                                                                                      
Dans sample_from_plots_beta(feature_dir = feature_dir, list_features = list_features,  :                                                                                                                                                                                        
  NAs introduits lors de la conversion automatique                                                                                                                                                                                                                              
Exécution arrêtée        

Since elimNull represents the name of the plots, it might happen that the user gives plot names that are of type string.

An alternative to that line, to remove plots with no data from the sample_beta_terra list could be :

 if (length(elimNull)>0)
   
    for (name in names(elimNull))
    {
        id_to_remove <- which(samples_beta_terra==name)
        if (length(id_to_remove) != 0L) {
            samples_beta_terra <- samples_beta_terra[- id_to_remove]
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions