R-alpha: Re: R/R-minus incompatibility [ an old one ]

Paul Gilbert pgilbert@bank-banque-canada.ca
Mon, 10 Nov 1997 11:43:11 -0500

>> x[["f"]]<-1
 >> zz<-"g"
 >In R both variants fail unless the name is already on the list. The
 >first one can be replaced by x$f, but there's seems to be no
 >substitute for the other one (oh yes I found one, but it's not fit to

A long time ago it seems it was decided to remain incompatible with S on
this, I think because  people often do this in error. (Indeed, it did
point out some errors in my code.) However, there were some instances in
my code where I did something like x[[c("f","g","h")]] <- 1:3 and wanted
the corresponding elements updated or inserted as appropriate.  I have
replaced those instances with listadd(x, c("f","g","h")) <- 1:3 where
listadd is as defined below (more or less as suggested by Ross or Robert
at the time). It is one of the functions in the compatibility code I
have circulated previously.

Paul Gilbert
   "list.add<-" <- function(x, replace, value)
     {# replace or add elements to a list.
      if (is.numeric(replace))
        {x[[replace]] <- value
      if (is.null(value))  value <- list(NULL)
      if (!is.list(value)) value <- list(value)
      if (1 == length(value))
       {for (i in seq(length(replace)))
          x<- do.call("$<-", list(x,replace[i],value[[1]]))
        {if(length(value) != length(replace) )
         stop("number of replacement values != number of elements to
         for (i in seq(length(replace)))
            x<- do.call("$<-", list(x,replace[i],value[[i]]))

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