[R] 0.63 naming list elements

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Nov 18 17:36:03 CET 1998


Dick Repasky <drepasky at bio.indiana.edu> writes:

> The following used to work (0.62.1 the latest that I used), and now
> it doesn't (0.63.0):
> 
> 
> force <- vector(mode = "list", length = 1)
> names(force)[1] <- somename
> 
> It returns the error:
> Error in "[<-"(NULL, 1) : object is not subsetable
> 
> 
> You might argue that this approach is unnecessary now that R allows
> subscripts that are out of range (e.g., force<-list(); force[["name"]] <- 42)
> but I changed a lot of code to work as above, and I really don't like
> the idea of reverting.

I don't think it's healthy to try and subset NULL... You could use
just

force <- vector(mode = "list", length = 1)
names(force) <- somename

or, for general length vectors,

force <- vector(mode = "list", length = k)
names(force) <- character(k)
for (i in 1:k) 
	names(force)[i]<- something.dependent.on(i)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list