# R/HowManySeparateContinents.R In laurasoul/dispeRse: Models For Paleobiogeography

#### Documented in HowManySeparateContinents

```#' How many separate continents are there
#'
#' Given a minimum separation between continental centres records how many separate continents exist
#'
#' @param min_separation Minimum separation allowed between continental centres in kilometres.
#' @param longitudes A vector of the decimalised longitudes for each continental centre.
#' @param latitudes A vector of the decimalised latitudes for each continental centre.
#' @return A vector of length equal to the number of separate continents.
#' @details Nothing yet.
#' @author Graeme T. Lloyd \email{graemetlloyd@@gmail.com}
#' @export
#' @examples
#' HowManySeparateContinents(100, c(179, -179), c(-89, 89))

HowManySeparateContinents <- function(min_separation, longitudes, latitudes, EarthRad = 6367.4447) {

# Add row and column names to matrix:

# If there are no joined continents:

# Simply output a vector of numbers (one for each separate continent):

# If there are joined continents:
} else {

# Create empty character vector to store each set of joined continents:
output <- vector(mode="character")

# Whilst there are remaining continental links to delineate:

# First find the (first) remaining continent with the most links to other continents:

# If there are multiple continents define the clump by those continents that form direct links to the first continent:

# Enumerate remaining continents (not directly linked to first continent):

# If there are continents left to delineate:
if(length(remaining_continents) > 0) {

# For each remaining continent:
for(i in remaining_continents) {

# If the continent is linked to any continent already part of the current clump:
if(length(sort(match(names(which(intercontinental_links[i, ] == 1)), largest_clump))) > 0) {

largest_clump <- c(largest_clump, i)

}

}

# Update remaining continents:

}

# Add current continental clump to output:
output <- c(output, paste(sort(largest_clump), collapse="&"))

# Find rows to delete:

# Remove current continental clump from links matrix:

# Catch issue if no longer a matrix and force back into a 1-by-1 matrix: