I have a value which can be one of 3 strings, or NULL. When the value is NULL the following code does not work
value <- NULL
if( value == "test" ){
print("1")
} else {
print("2")
}
It seems I have to write the code as below to make it work:
if ( !is.null(value) && value== "test" ) {
print("1")
} else {
print("2")
}
Writing it like that however seems unnecessarily complicated and messy.
Is there a cleaner way to do this?