From plummer@iarc.fr  Mon Sep  8 08:48:19 1997
From: plummer@iarc.fr (Martyn Plummer)
Date: Mon, 08 Sep 1997 09:48:19 +0200 (MET DST)
Subject: R-alpha: Assingment to list or vector elements
Message-ID: <XFMail.970908104926.plummer@iarc.fr>

When you assign a value to an object which exists in some database on
the search list, R creates a copy in the current environment. However,
if the object is a list or vector, and you assign a new value to one of
its elements, a copy is not made and the assignment fails (with no error
message!).  This behaviour is incompatible with S-PLUS, which will make
a copy of the object before modifying one of its elements.

Martyn

> exists("alist", 1, inherits=F)
[1] FALSE
> mydata <- list(alist = list(one=1,two=1))
> attach(mydata)
> alist
$one
[1] 1

$two
[1] 1

> alist$one <- 2
> alist[[2]] <- 3
> alist
$one
[1] 1

$two
[1] 1

> exists("alist", 1, inherits=F)
[1] FALSE
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: Assingment to list or vector elements
Martyn Plummer