hb@maths.lth.se
2002-Jul-08  22:49 UTC
as.character.octmode() and format.octmode() (PR#1759)
Full_Name: Henrik Bengtsson
Version: 1.5.1
OS: WinMe
Submission from: (NULL) (217.210.0.243)
PROBLEM:
With
  x <- 0; class(x) <- "octmode"
Should 
  as.character(x)
and
  format(x)
give "" and not "0"?
SUGGESTION/SOLUTION:
Here is one fix that gives "0" instead:
as.character.octmode <- function(x, ...) {
  if (!inherits(x, "octmode"))
    stop("calling wrong method")
  isna <- is.na(x)
  y <- x[!isna]
  ans0 <- character(length(y))
  z <- NULL                          # FIX 01
  while (any(y > 0) | is.null(z)) {  # FIX 02
    z <- y%%8
    y <- floor(y/8)
    ans0 <- paste(z, ans0, sep="")
  }
  ans <- rep(as.character(NA), length(x))
  ans[!isna] <- ans0
  ans
}
Same for format.octmode().
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._