ourMELONS/R/initPopNames.R
Waldir Leoncio fca9caa731 Restyled files
Ran through styler::style_dir() in the R and tests directories in preparation for #23.
2021-11-10 14:25:50 +01:00

37 lines
988 B
R
Raw Blame History

#' @title Initialize Pop Names
#' @param nameFile nameFile
#' @param indexFile indexFile
#' @export
initPopNames <- function(nameFile, indexFile) {
# Palauttaa tyhj<68>n, mik<69>li nimitiedosto ja indeksitiedosto
# eiv<69>t olleet yht?pitki?
indices <- load(indexFile)
fid <- load(nameFile)
if (fid == -1) {
# File didn't exist
stop("Loading of the population names was unsuccessful")
}
line <- readLines(fid)[1]
counter <- 1
names <- vector()
while ((line != -1) & (line != "")) {
names[counter] <- line
line <- readLines(fid)[counter]
counter <- counter + 1
}
if (length(names) != length(indices)) {
cat("The number of population names must be equal to the number of")
cat("entries in the file specifying indices of the first individuals")
cat("of each population.")
}
popnames <- cell(length(names), 2)
for (i in 1:length(names)) {
popnames[i, 1] <- names[i]
popnames[i, 2] <- indices[i]
}
return(popnames)
}