From savicky at cs.cas.cz  Mon Dec 21 18:41:13 2009
From: savicky at cs.cas.cz (savicky at cs.cas.cz)
Date: Mon, 21 Dec 2009 18:41:13 +0100 (CET)
Subject: [Rd] a little bug for the function 'sprintf' (PR#14161)
Message-ID: <20091221174113.EBAE9282C76A@mail.pubhealth.ku.dk>

> When you type in the example codes:
> 
> > sprintf("%s is %f feet tall\n", "Sven", 7.1)
> 
> and R returns:
> 
> [1] "Sven is 7.100000 feet tall\n"
> 
> this is very different from the 'sprintf' function in C/C++, for in C/C++,
> the format string "\n" usually represents a new line, but here, just
> the plain text "\n"!

The function sprintf() produces a string, which is then printed
using R formatting. You probably expected the following.

  > cat(sprintf("%s is %f feet tall\n", "Sven", 7.1))
  Sven is 7.100000 feet tall

Compare also 

  > s <- sprintf("%s is %f feet tall\n", "Sven", 7.1)
  > cat(s)
  Sven is 7.100000 feet tall
  > print(s)
  [1] "Sven is 7.100000 feet tall\n"
  > 

PS.



[Rd] a little bug for the function 'sprintf' (PR#14161)
savicky at cs.cas.cz