From hadley at rice.edu  Fri Jul 22 21:45:32 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Fri, 22 Jul 2011 14:45:32 -0500
Subject: [Rd] Best practices for writing R functions
In-Reply-To: <6441154A9FF1CD4386AF4ABF141A056D265A9E9B@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
References: <1311341191873-3686674.post@n4.nabble.com>
	<4E2993CE.4020903@prodsyse.com>
	<CADwqtCONeEqXTTg0OyDj=OJWeQxNKBm79M=iBg1jdy6JtO_w0Q@mail.gmail.com>
	<6441154A9FF1CD4386AF4ABF141A056D265A9E9B@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
Message-ID: <CABdHhvHvB4vV5BymZfSguxCUH745nd6mrAk8EDw8Kk3RPN-C2Q@mail.gmail.com>

> But beware that a function makes a copy of the argument as soon as you try to modify something in that argument. So, for example, if you have a big list object as an argument and are going to modify one element in the list, you will save memory by making a local copy of the single element and modifying that. However, as others have said, I would not worry until you find there is a problem.

That's generally good practice in R - always modify the simplest
object possible.

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



[Rd] Best practices for writing R functions
Hadley Wickham