Re: [R] Possible Improvement to sapply

2018-03-14 Thread Doran, Harold
re, the first part of the >'Subject' of this mailing list thread, "Possible Improvement", >*has* become true after all -- > >-- thanks to Henrik ! > >Martin Maechler >ETH Zurich > > > >> On Tue, Mar 13, 2018 at 9:21 AM, Doran, Harold <hdo...@air.org> wr

Re: [R] Possible Improvement to sapply

2018-03-14 Thread Martin Maechler
ork I was doing, > > however, I wonder if there is a way such that sapply could avoid the > > overhead of having to call the identical function to determine the > > conditional path. > > > > > > > > From: William Dunlap [mailto:wdun...@tibco.com] > > Se

Re: [R] Possible Improvement to sapply

2018-03-13 Thread Henrik Bengtsson
m] > Sent: Tuesday, March 13, 2018 12:14 PM > To: Doran, Harold <hdo...@air.org> > Cc: Martin Morgan <martin.mor...@roswellpark.org>; r-help@r-project.org > Subject: Re: [R] Possible Improvement to sapply > > Could your code use vapply instead of sapply? vapply forces you

Re: [R] Possible Improvement to sapply

2018-03-13 Thread William Dunlap via R-help
:martin.mor...@roswellpark.org] > Sent: Tuesday, March 13, 2018 9:43 AM > To: Doran, Harold <hdo...@air.org>; 'r-help@r-project.org' < > r-help@r-project.org> > Subject: Re: [R] Possible Improvement to sapply > > > > On 03/13/2018 09:23 AM, Doran, Harold wrote: >

Re: [R] Possible Improvement to sapply

2018-03-13 Thread Martin Maechler
sday, March 13, 2018 12:11 PM > To: Doran, Harold <hdo...@air.org> > Cc: r-help@r-project.org > Subject: Re: [R] Possible Improvement to sapply > Wouldn't that change how simplify='array' is handled? >> str(sapply(1:3, function(x)diag(x,5,2), simplify=&

Re: [R] Possible Improvement to sapply

2018-03-13 Thread Doran, Harold
, March 13, 2018 12:14 PM To: Doran, Harold <hdo...@air.org> Cc: Martin Morgan <martin.mor...@roswellpark.org>; r-help@r-project.org Subject: Re: [R] Possible Improvement to sapply Could your code use vapply instead of sapply? vapply forces you to declare the type and dimensions of

Re: [R] Possible Improvement to sapply

2018-03-13 Thread Doran, Harold
You’re right, it sure does. My suggestion causes it to fail when simplify = ‘array’ From: William Dunlap [mailto:wdun...@tibco.com] Sent: Tuesday, March 13, 2018 12:11 PM To: Doran, Harold <hdo...@air.org> Cc: r-help@r-project.org Subject: Re: [R] Possible Improvement to sapply Wo

Re: [R] Possible Improvement to sapply

2018-03-13 Thread William Dunlap via R-help
Wouldn't that change how simplify='array' is handled? > str(sapply(1:3, function(x)diag(x,5,2), simplify="array")) int [1:5, 1:2, 1:3] 1 0 0 0 0 0 1 0 0 0 ... > str(sapply(1:3, function(x)diag(x,5,2), simplify=TRUE)) int [1:10, 1:3] 1 0 0 0 0 0 1 0 0 0 ... > str(sapply(1:3,

Re: [R] Possible Improvement to sapply

2018-03-13 Thread Doran, Harold
. -Original Message- From: Martin Morgan [mailto:martin.mor...@roswellpark.org] Sent: Tuesday, March 13, 2018 9:43 AM To: Doran, Harold <hdo...@air.org>; 'r-help@r-project.org' <r-help@r-project.org> Subject: Re: [R] Possible Improvement to sapply On 03/13/2018 09:23 AM, D

Re: [R] Possible Improvement to sapply

2018-03-13 Thread Martin Morgan
On 03/13/2018 09:23 AM, Doran, Harold wrote: While working with sapply, the documentation states that the simplify argument will yield a vector, matrix etc "when possible". I was curious how the code actually defined "as possible" and see this within the function if (!identical(simplify,

[R] Possible Improvement to sapply

2018-03-13 Thread Doran, Harold
While working with sapply, the documentation states that the simplify argument will yield a vector, matrix etc "when possible". I was curious how the code actually defined "as possible" and see this within the function if (!identical(simplify, FALSE) && length(answer)) This seems superfluous