Number formatting in concatenation of sqldf in R

I would like to understand the formatting, which is applied to a number, which is included in a concatenated string in sqldf.
I would like to know how one could replicate the output with base R, so basically it rounds to 0 digits, but prints out the first digit nonetheless.

library(sqldf)
sqldf("SELECT (' - tx: '||round(2152.918349)) as test")
           test
1  - tx: 2153.0

If I would just round this number using R without sqldf, it would just be printed out as an integer.

 print(round(2152.918349))
 [1] 2153

So most probably sqldf applies some additional formatting on the number, but I could not find any documentation on what exactly it is doing there.

>Solution :

For base R to print the same number as sqldf, use sprintf:

sprintf("%.1f", round(2152.918349))

# [1] "2153.0"

Leave a Reply