[R] rename and concatenate name of columns

R. Michael Weylandt michael.weylandt at gmail.com
Sun Jun 16 14:17:36 CEST 2013

On Sat, Jun 15, 2013 at 1:45 AM, David Winsemius <dwinsemius at comcast.net> wrote:
> On Jun 14, 2013, at 1:25 PM, Bert Gunter wrote:
>> For the record:
>> ...
>> ------------
>>> A bit of commentary: Something did happen. It's just that you didn't do anything with _what_ happened. The copy of the 'dataset'-object got modified but you never returned it from the function, and and also didn't reassign it to the original 'dataset'. Functions return their last assignment.
> This line was probably more worthy of criticism. Functions return the result of last evaluated expression. (Which is often not what the beginning R programmer expected.)
>>> In the case of the 'for'-function, it somewhat surprisingly returns a NULL. It is a rather odd function in the functional R world, since its main role in life is doing things by side-effects,
>> ---------
>> for() is **not** a function.
>> ?"for" describes it as a "basic control-flow [sic] construct."

Which is implemented as a function in C, as can be seen by examining
the table in names.c. It fails, however, to be a closure as are most
things which are defined with the "function" keyword in R.

That is, admittedly, only an implementation detail and cannot be found
(on brief examination) in the language definition.

> Nonetheless it does return NULL.
>> Ergo, it's behavior is not odd.
> That remains a matter of opinion.

Note that the "foreach" developers do take advantage of foreach()
returning a value, so there's at least some reason to expect "for"
could return a value. I could also see a case being made for
consistency with if/else.


More information about the R-help mailing list