From r.turner at auckland.ac.nz  Wed Mar 29 06:04:36 2017
From: r.turner at auckland.ac.nz (Rolf Turner)
Date: Wed, 29 Mar 2017 17:04:36 +1300
Subject: [Rd] A trap for young players with the lapply() function.
In-Reply-To: <CAF8bMcYBhtpRVYo37ABjzko1sfbK0ck27c03xJ-kqpniykPjww@mail.gmail.com>
References: <b2f95986-2a82-e9d7-d5a2-32ffac793461@auckland.ac.nz>
	<alpine.OSX.2.20.1703271912020.6811@charles-berrys-macbook.local>
	<0242d8a3-8d74-2036-e9a8-d1bfbd8aaef5@auckland.ac.nz>
	<CAF8bMcYBhtpRVYo37ABjzko1sfbK0ck27c03xJ-kqpniykPjww@mail.gmail.com>
Message-ID: <a163315d-da49-4bd5-13f1-573b06da64fc@auckland.ac.nz>


On 29/03/17 11:03, William Dunlap wrote:

>> I think that the suggestion I made, in response to a posting by
>> Barry Rowlingson, that the first argument of lapply() be given the name of
>> ".X" rather than just-plain-X, would be (a) effective, and (b) harmless.
>
> It would break any call to *apply() that used X= to name the first
> argument. There are currently 3020 such calls in the R code in CRAN.

Okay.  Scratch that idea.

> One can avoid the problem by creating the function given as the FUN
> argument when one calls lapply() and the like.  Don't give that
> function arguments named "X", "FUN", "USE.NAMES", etc. and perhaps
> make use of R's lexical scoping to avoid having to use many arguments
> to the function.  E.g., instead of
>     sapply(1:5, sin)
> use
>     sapply(1:5, function(theta) sin(theta))
> or instead of
>     myY <- 3
>     sapply(1:5, atan2, y=myY)
> use
>     myY <- 3
>     sapply(1:5, function(x) atan2(myY, x))

Again, all very sound advice but it does not address the problem of 
there being a trap for young players.  The advice can only be applied by 
a user only if the user is *aware* of the trap.

At this point it would appear that the problem is fundamentally 
unsolvable. :-(

cheers,

Rolf

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



[Rd] A trap for young players with the lapply() function.
Rolf Turner