Hi All,

My sample code looks like

options(stringsAsFactors = FALSE);
clean = function(x)
{
    loc = agrep("ABC", x$name);
    x[loc,]$new_name <- "NEW";
    x;
}

name = c("12", "dad", "dfd");
y = data.frame(name = as.character(name), idx = 1:3);
y$new_name = y$name;

z <- clean(y)

The snippet does not work because I forgot to test the return value of agrep. If no pattern is found, it returns 0 and the following x[loc, ]$new_name does not like. I know how to fix that part. However, my code has many places like that, say over 100 calls for agrep or grep for different patterns and substitution. Is there any smart way to fix them all rather than line by line?

Many thanks.

HXD

	[[alternative HTML version deleted]]

