sprintf invalid format '%d'
This works: > sprintf('%d', c(1, 1.5)) [1] "1" "1" and this doesn't: > sprintf('%d', c(1.5, 1)) Error in sprintf("%d", c(1.5, 1)) : invalid format '%d'; use format %f, %e, %g or %a for numeric objects Why? Mikael Jumppanen This is actually really interesting question. To start, %d stands for integer. The vector argument is recycled if possible but if it is c(1.5, 1) it will fail when sprintf() tries to replace %d with 1.5 (which is not integer). I thought it might be related to the fact that in R both integer and double are numeric mode, for example: storage.mode(c(1.5, 1)) # [1] "double"