[Rd] sprintf, check number of parameters
matthias-gondan
m@tth|@@-gond@n @end|ng |rom gmx@de
Wed Nov 4 17:32:51 CET 2020
Now that you ask, no real use case comes to my mind in which an argument is skipped in one language but not another. Thank you for implementing the warning, I guess it will be useful on the long run.Best wishesMatthias
-------- Ursprüngliche Nachricht --------Von: Tomas Kalibera <tomas.kalibera using gmail.com> Datum: 04.11.20 16:26 (GMT+01:00) An: matthias-gondan <matthias-gondan using gmx.de>, r-devel using r-project.org Betreff: Re: [Rd] sprintf, check number of parameters
Dear Matthias,
On 11/4/20 4:01 PM, matthias-gondan
wrote:
Dear Tomas,
Thank you.
Regarding the "unnumbered" arguments, i.e.
sprintf('%f %f', 1, 2, 3). This was the case I wanted to report,
here a warning can be very useful.
Regarding the "numbered" arguments, that is,
sprintf('%$1f %$3f', 1, 2, 3). Here, omission of an argument
might be intended, for example, in an application with support
for multiple languages. Therefore, I am wondering if a warning
should be raised.
It is rather "%$1f", etc.
Say GCC warns also on unused arguments with numbered references
("unused arguments in $-style format"). I have not yet received
any feedback from package maintainers who would have found a
problem with the new warning for message translation. Would you
have an example pattern that should be supported? Shouldn't all
arguments be used, anyway, just possibly in different order?
Unless there is a strong reason to do otherwise, I would rather
not introduce more deviations from the C behavior. Of course,
technically it would be simple: not print a warning when there is
at least one numbered reference.
Best
Tomas
Regarding the mixture: never heard that this
works, and I would probably not want to use it...
Your work is much appreciated, thanks again.
Best regards,
Matthias
-------- Ursprüngliche Nachricht --------
Von: Tomas Kalibera <tomas.kalibera using gmail.com>
Datum: 04.11.20 15:43 (GMT+01:00)
An: Matthias Gondan <matthias-gondan using gmx.de>,
r-devel using r-project.org
Betreff: Re: [Rd] sprintf, check number of parameters
Dear Matthias,
thanks for the suggestion, R-devel now warns on unused arguments
by
format (both numbered and un-numbered). It seems that the new
warning is
useful, often it finds cases when arguments were accidentally
passed to
sprintf but had been meant for a different function.
R allows combining both numbered and un-numbered references in a
single
format, even though it may be better to avoid and POSIX does not
allow
that.
Best
Tomas
On 9/20/20 1:03 PM, Matthias Gondan wrote:
> Dear R developers,
>
> I am wondering if this should raise an error or a warning.
>
>> sprintf('%.f, %.f', 1, 2, 3)
> [1] "1, 2"
>
> I am aware that R has „numbered“ sprintf arguments
(sprintf('%1$.f', …), and in that case, omissing of specific
arguments may be intended. But in the usual syntax, omission of an
argument is probably a mistake.
>
> Thank you for your consideration.
>
> Best wishes,
>
> Matthias
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
[[alternative HTML version deleted]]
More information about the R-devel
mailing list