Skip to content
Prev 53525 / 63424 Next

Inconsistency in handling of numeric input with %d by sprintf

Consider

#as.numeric for emphasis
sprintf('%d', as.numeric(1))
# [1] "1"

vs.

sprintf('%d', NA_real_)
invalid format '%d'; use format %f, %e, %g or %a for numeric object
I understand the error is correct, but if it works for other numeric input,
why doesn't R just coerce NA_real_ to NA_integer_?

Michael Chirico