diff --git a/NAMESPACE b/NAMESPACE index 13f1ad8..70e107a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,7 @@ export(computeRows) export(etsiParas) export(greedyMix) export(handleData) +export(initPopNames) export(inputdlg) export(isfield) export(laskeMuutokset4) diff --git a/R/greedyMix.R b/R/greedyMix.R index 16f735f..1939e69 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -1000,49 +1000,6 @@ greedyMix <- function( # %----------------------------------------------------------------------------------- - -# function popnames = initPopNames(nameFile, indexFile) -# %Palauttaa tyhj�n, mik�li nimitiedosto ja indeksitiedosto -# % eiv�t olleet yht?pitki? - -# popnames = []; -# indices = load(indexFile); - -# fid = fopen(nameFile); -# if fid == -1 -# %File didn't exist -# msgbox('Loading of the population names was unsuccessful', ... -# 'Error', 'error'); -# return; -# end; -# line = fgetl(fid); -# counter = 1; -# while (line ~= -1) & ~isempty(line) -# names{counter} = line; -# line = fgetl(fid); -# counter = counter + 1; -# end; -# fclose(fid); - -# if length(names) ~= length(indices) -# disp('The number of population names must be equal to the number of '); -# disp('entries in the file specifying indices of the first individuals of '); -# disp('each population.'); -# return; -# end - -# popnames = cell(length(names), 2); -# for i = 1:length(names) -# popnames{i,1} = names(i); -# popnames{i,2} = indices(i); -# end - - -# %----------------------------------------------------------------------------------- - - -# %-------------------------------------------------------------------------- - # function logml = ... # initialCounts(partition, data, npops, rows, noalle, adjprior) diff --git a/R/initPopNames.R b/R/initPopNames.R new file mode 100644 index 0000000..47dd2f8 --- /dev/null +++ b/R/initPopNames.R @@ -0,0 +1,37 @@ +#' @title Initialize Pop Names +#' @param nameFile nameFile +#' @param indexFile indexFile +#' @export +initPopNames <- function(nameFile, indexFile) { + # Palauttaa tyhj�n, mik�li nimitiedosto ja indeksitiedosto + # eiv�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) +} \ No newline at end of file diff --git a/man/initPopNames.Rd b/man/initPopNames.Rd new file mode 100644 index 0000000..779f644 --- /dev/null +++ b/man/initPopNames.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/initPopNames.R +\name{initPopNames} +\alias{initPopNames} +\title{Initialize Pop Names} +\usage{ +initPopNames(nameFile, indexFile) +} +\arguments{ +\item{nameFile}{nameFile} + +\item{indexFile}{indexFile} +} +\description{ +Initialize Pop Names +}