Doug Fir Doug Fir - 1 month ago 16
R Question

r { : argument is of length zero (already tried !is.null()

If i contains substring 'log' then errors should be 'log' else should be 'not log'.

i <- "master_sink"
islog <- grep("log", i)

if( islog==1 ) {
errors <- 'log'
} else {
errors <- 'not log'
}
Error in if (islog == 1) { : argument is of length zero


So tried:

if( !is.null(islog) && islog==1 ) {
errors <- 'log'
} else {
errors <- 'not log'
}
Error in if (!is.null(islog) && islog == 1) { :
missing value where TRUE/FALSE needed


I have tried many variations after reading several SO posts but I keep getting errors.

Answer

Try if(length(islog) > 0), or grepl("log", i), which returns TRUE/FALSE.