##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (name, outfile, type = "int")
{
matchlines <- grep(name, outfile, ignore.case = TRUE, value = TRUE)
if (type == "calc") {
return(as.numeric(NA))
}
if (length(matchlines) > 1) {
warning(paste("More than one match found for parameter: ",
name, sep = ""))
return(matchlines)
}
else if (length(matchlines) == 0) {
warning(paste("Parameter not found: ", name, sep = ""))
return(as.numeric(NA))
}
if (type == "int") {
regexp <- "-*\d+"
}
else if (type == "dec") {
regexp <- "-*\d+\.\d+"
}
else if (type == "str") {
regexp <- paste(name, ".*", sep = "")
}
start <- regexpr(regexp, matchlines[1], perl = TRUE)
if (type == "str") {
returnVal <- as.character(sub(name, "", matchlines[1],
ignore.case = TRUE))
}
else returnVal <- as.numeric(substr(matchlines[1], start,
start + attr(start, "match.length")))
return(returnVal)
}
Run the code above in your browser using DataLab