[R] Function to modify existing data.frame--Improving R Language
Peter Muhlberger
peterm at andrew.cmu.edu
Wed Jan 19 18:27:19 CET 2005
Thanks to everyone who replied to my question!
A comment regarding Thomas's point below: Java & other object-oriented
languages that are function rather than macro based usually provide methods
& other capabilities that allow pass by reference in certain cases and these
methods would solve the problem I posed regarding how to change values in an
existing data.frame from within a function. In Java, for example, objects
pass by reference, so I could easily transfer a dataset to a function & have
it efficiently changed. In Visual Basic, one could indicate whether a
variable was being passed by reference or value. By not allowing any
straightforward passing by reference, R strikes me as a lot less flexible &
useful than it might be. A basic operation in other stats languages is to
update a dataset using a program. This proves very helpful for managing
data and setting up analyses. But, this seems to be quite inelegant to do
in R.
Peter
On 1/19/05 6:16 AM, "r-help-request at stat.math.ethz.ch" From: Thomas Lumley
<tlumley at u.washington.edu>
<r-help-request at stat.math.ethz.ch> wrote:
> Yes and no.
>
> This isn't so much a question of pass-by-reference, as one reply
> suggested, but of macros vs functions.
>
> Stata is (largely) a macro language: it does operations on command strings
> and then evaluates them. It's not that Stata programs work with
> references, it's that all objects (except local macros) are global.
>
> R is based on functions: it evaluates arguments and then operates on
> them. When you have functions, with local variables, it then becomes
> relevant to ask whether the arguments to the function are just copies or
> are references to the real thing. In R they are just copies (from a
> language point of view) but are often references from an efficiency point
> of view.
More information about the R-help
mailing list