Re: [R] A question on Programming

2011-11-11 Thread Steve Lianoglou
Hi, On Fri, Nov 11, 2011 at 7:26 AM, Oliver wrote: > Christofer Bogaso gmail.com> writes: > [...] >> Here my question is, is there any speed reduction if I put them within a >> function (I think there may be some speed reduction at least within >> for-loop, because that loop needs to call that f

Re: [R] A question on Programming

2011-11-11 Thread Oliver
Christofer Bogaso gmail.com> writes: [...] > Here my question is, is there any speed reduction if I put them within a > function (I think there may be some speed reduction at least within > for-loop, because that loop needs to call that function many times), > relative to if I used that group of c

Re: [R] A question on Programming

2011-11-10 Thread R. Michael Weylandt
Dr Murdoch, You're absolutely correct -- my apologies. Michael On Thu, Nov 10, 2011 at 10:44 AM, Duncan Murdoch wrote: > On 10/11/2011 10:28 AM, R. Michael Weylandt wrote: >> >> Yes, there will be some reduction in speed: >> >> E.g., >> >> >  system.time(replicate(1e5, (function() sum(1:10))())

Re: [R] A question on Programming

2011-11-10 Thread Duncan Murdoch
On 10/11/2011 10:28 AM, R. Michael Weylandt wrote: Yes, there will be some reduction in speed: E.g., > system.time(replicate(1e5, (function() sum(1:10))())) user system elapsed 0.696 0.022 0.729 > system.time(replicate(1e5, sum(1:10))) user system elapsed 0.292 0.006 0

Re: [R] A question on Programming

2011-11-10 Thread jim holtman
You can always runs a quick test. Here a loop is repeated 10M times and the cost of the function call adds 344 ns; is this significant in your case? Probably not for the modularity that is gained. For your 10,000 loops, it would add 3.44 ms to the overall run (less than an blink of the eye). >

Re: [R] A question on Programming

2011-11-10 Thread Joshua Wiley
Hi Christofer, Any speed reduction should be relatively small, and the advantage in terms of easily maintainable, clearly understandable code will be enormous. If the function you make from the code does not have any methods and you are concerned about a slow down related to your loop repeatedly

Re: [R] A question on Programming

2011-11-10 Thread R. Michael Weylandt
Yes, there will be some reduction in speed: E.g., > system.time(replicate(1e5, (function() sum(1:10))())) user system elapsed 0.696 0.022 0.729 > system.time(replicate(1e5, sum(1:10))) user system elapsed 0.292 0.006 0.306 But it's not much: 3 tenths of a second for 10,000 ca

Re: [R] A question on Programming

2011-11-10 Thread Sarah Goslee
Hi, On Thu, Nov 10, 2011 at 10:07 AM, Christofer Bogaso wrote: > Dear all. Let say I have a group of codes which will be used in many places > in my overall R-code files. These group of codes will be used within a > for-loop (with a big length, like 1 times) and also many other places > outsi