better pattern detection

This commit is contained in:
2015-01-12 14:59:51 +01:00
parent 714845a8f0
commit fd4ea4a47e
2 changed files with 40 additions and 1 deletions
+21
View File
@@ -19,6 +19,27 @@ insertRow <- function(existingDF, newrow, r) {
return(existingDF)
}
convertLogical0 <- function(var) {
if(is.integer(var) && length(var) == 0) {
var <- 0
}
return(var)
}
smartPatternMatch <- function(string, pattern, chars) {
if(chars < 5) {
found <- agrep(pattern, string, max.distance = list(all = 0), ignore.case = TRUE)
}
if(chars > 7) {
found <- agrep(pattern, string, max.distance = list(all = 2), ignore.case = TRUE)
}
else {
found <- agrep(pattern, string, max.distance = list(all = 1), ignore.case = TRUE)
}
found <- convertLogical0(found)
return(found)
}
## ERROR HANDLING
# Check for empty API returns (0 or 1 or 2)