Ok, I guess that clears it up then. Thanks Ben and Simon for the
explanation! I should have guessed that since it's "a wrapper for the
system sprintf C-library function" discrepancies would be likely to simply
be system dependent.

I saw that the R docs describe the 0 flag with the phrase 'For numbers...'
but since it didn't actually say what would happen with non-numbers I
wasn't entirely sure. It would be clearer (IMHO) if it said something
explicit like "For characters, the behavior will be platform dependent.", I
guess.

- Joran

On Tue, Apr 24, 2012 at 2:12 PM, Simon Urbanek
<simon.urbanek@r-project.org>wrote:

>
> On Apr 24, 2012, at 4:24 PM, Joran Elias wrote:
>
> > I stumbled across this by accident from this StackOverflow question:
> >
> > http://stackoverflow.com/q/10300325/324364
> >
> > and a subsequent discussion in the StackOverflow R chat room:
> >
> > http://chat.stackoverflow.com/transcript/message/3431991#3431991
> >
> > The issue is the output from the following code:
> >
> > sprintf('%05s',as.character(1:5))
> >
> > It appears that when this is run in OS X in either 2.14.2 or 2.15.0, the
> > output is:
> >
> > [1] "00001" "00002" "00003" "00004" "00005"
> >
> > whereas when it is run on other platforms (I saw examples from various
> > Windows versions and one user on Ubuntu, all using 2.15.0 I believe) you
> > get:
> >
> > [1] "    1" "    2" "    3" "    4" "    5"
> >
> > There was some uncertainty as to which behavior is "expected".
>
> The behavior of "%0s" is undefined -- this is documented both by R and
> POSIX (arguably more clearly in the latter), so any behavior should be
> expected.
>
>
> > Does anyone
> > have any insight into which behavior is "correct" and whether this is a
> bug
> > or not?
> >
>
> It is not a bug. The formatting is done by the OS, so the results are
> always OS-dependent -- since %0s is undefined, the OS can choose to
> interpret it any way it wants.
>
> Cheers,
> Simon
>
>
>

	[[alternative HTML version deleted]]

