From wdunlap at tibco.com  Thu Aug 26 02:31:27 2010
From: wdunlap at tibco.com (William Dunlap)
Date: Wed, 25 Aug 2010 17:31:27 -0700
Subject: [Rd] No [[<-.factor()
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D700035B3C70@NA-PA-VBE03.na.tibco.com>

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 



[Rd] No [[<-.factor()
William Dunlap