ourMELONS/R/lueNimi.R

23 lines
740 B
R
Raw Permalink Normal View History

2020-06-24 16:10:14 +02:00
#' @title Read the Name
#' @description Returns the part of the line from the beginning that is before the comma. Useful for returning the name of a GenePop area
2020-06-24 16:10:14 +02:00
#' @param line line
#' @return nimi
lueNimi <- function(line) {
# ==========================================================================
# Validation
# ==========================================================================
if (!grepl(",", line)) {
stop("There are no commas in this line")
}
# Palauttaa line:n alusta sen osan, joka on ennen pilkkua.
n <- 1
merkki <- substring(line, n, n)
nimi <- ""
while (merkki != ",") {
nimi <- c(nimi, merkki)
n <- n + 1
merkki <- substring(line, n, n)
}
return(paste(nimi, collapse = ""))
}