From luke-tierney at uiowa.edu  Mon Mar  2 00:48:06 2015
From: luke-tierney at uiowa.edu (luke-tierney at uiowa.edu)
Date: Sun, 1 Mar 2015 17:48:06 -0600
Subject: [Rd] iterated lapply
In-Reply-To: <CAF8bMcbu93drmsDEc6DpSiKpb1sx-ufMZhC81Z5pp+c4ZzpxFw@mail.gmail.com>
References: <mailman.21.1424775604.19275.r-devel@r-project.org>
	<20150224113908.GA7612@cs.toronto.edu>
	<alpine.DEB.2.02.1502240950150.2336@luke-Latitude>
	<CAF8bMcbu93drmsDEc6DpSiKpb1sx-ufMZhC81Z5pp+c4ZzpxFw@mail.gmail.com>
Message-ID: <alpine.DEB.2.02.1503011742280.2327@luke-Latitude>

On Thu, 26 Feb 2015, William Dunlap wrote:

> ...
> It also seems to cause problems with some built-in functions:
> newlapply <- function (X, FUN, ...)?
> {
> ? ? FUN <- match.fun(FUN)
> ? ? if (!is.list(X))?
> ? ? ? ? X <- as.list(X)
> ? ? rval <- vector("list", length(X))
> ? ? for (i in seq(along = X)) {
> ? ? ? ? rval[i] <- list(local({
> ? ? ? ? ? ? i <- i
> ? ? ? ? ? ? FUN(X[[i]], ...)
> ? ? ? ? }))
> ? ? }
> ? ? names(rval) <- names(X)
> ? ? return(rval)
> }
> newlapply(1:2,log)
> #Error in FUN(X[[i]], ...) : non-numeric argument to mathematical function

This seems to be a bug in log() -- this takes local() out of the issue:

> f <- function(x, ...) {
+     g <- function()
+         log(x, ...)
+     g()
+ }
> f(1)
Error in log(x, ...) : non-numeric argument to mathematical function

It's not following the ... properly for some reason.

Best,

luke

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


[Rd] iterated lapply
luke-tierney at uiowa.edu