Warning in is.na(r) || is.null(r) : 'length(x) = 3 > 1' in coercion to 'logical(1)'

I'm getting warning message with is.na(r), I don't know why, but if I deleted is.na(r) then it's working fine without any warnings.
r version : 4.2.1

translation_get_translation <- function(type, technical){
map <- translation_map()
r <- map [ which( map$TranslationType == type & map$TechnicalName == technical ) , ]
if (is.na(r) || is.null(r) || nrow(r) < 1){
log_debug("No translation map found ", type," " , technical)
} else {
if (nrow(r)>1){
log_debug("Multiple translation map found ", type," ", technical)

unlike is.null and nrow ; is.na is vectorised so perhaps you would use any(is.na(r)) so that it would be assessed to a singular output.
However, your program may still struggle depending on the input (map) something like list(NULL,NULL) as r would evaluate to NA which is neither TRUE nor FALSE ; though you probably would wish it to be false ? Its not clear what r would be expected to be, and so how to handle it.

any(is.na(r)) -- solves the above warning. And program is running successfully without any errors.

Many thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.