Should there be a [[<-.factor() that either throws
an error or acts like [<-.factor() to avoid making
an illegal object of class factor?

  > z <- factor(c("Two","Two","Three"), levels=c("One","Two","Three"))
  > z
  [1] Two   Two   Three
  Levels: One Two Three
  > str(z)
   Factor w/ 3 levels "One","Two","Three": 2 2 3
  > z[[2]] <- "One"
  > str(z) # the .Data part is now character
   Factor w/ 3 levels "One","Two","Three": 2 One 3
  > z
  [1] <NA> <NA> <NA>
  Levels: One Two Three
  > z[2] <- "One"
  Error in class(x) <- cx : adding class "factor" to an invalid object

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to