Fixed behavior of testaaPop

This commit is contained in:
Waldir Leoncio 2020-07-28 10:39:07 +02:00
parent d5637fe428
commit 7ce0110928

View file

@ -1,27 +1,19 @@
#' @title Test population
#' @description Test a line in the population
#' @param rivi Line
#' @return pal
#' @return pal = 1 if the line starts with one of the following
# letter combinations: Pop, pop, POP. In all others cases, pal = 0
#' @export
testaaPop <- function(rivi) {
# pal=1, mik<69>li rivi alkaa jollain seuraavista
# kirjainyhdistelmist? Pop, pop, POP. Kaikissa muissa
# tapauksissa pal=0.
if (length(rivi) < 3) {
if (nchar(rivi) < 3) {
pal <- 0
return(pal)
}
if (
all(rivi[1:3] == 'Pop') |
all(rivi[1:3] == 'pop') |
all(rivi(1:3)=='POP')
) {
pal <- 1
return(pal)
} else {
pal <- 0;
return(pal)
rivi_start <- substring(rivi, 1, 3)
pal <- ifelse(rivi_start %in% c('Pop', 'pop', 'POP'), 1, 0)
}
return(pal)
}