Skip to content
Prev 591 / 12125 Next

[R-pkg-devel] How to make S3-method for the "format" generic for class inheriting from "AsIs"

Thank you very much Hadley for your fast response!


I do however find the following lines (102-113) from "data.frame" a little
problematic here:

  [...]
  if (is.vector(xi1) || is.factor(xi1))
    xi[[j]] <- rep(xi1, length.out = nr)
  else if (is.character(xi1) && inherits(xi1, "AsIs"))
    xi[[j]] <- structure(rep(xi1, length.out = nr),
      class = class(xi1))
  else if (inherits(xi1, "Date") || inherits(xi1,
    "POSIXct")) 
    xi[[j]] <- rep(xi1, length.out = nr)
  else {
    fixed <- FALSE
    break
  }
  [...]


With the "as.data.frame.pin" as suggested, I will here get "fixed <-
FALSE" which will result in:

  > data.frame(1:2, structure("191212121212", class = c("pin",
"character")))
  Error in data.frame(1:2, structure("191212121212", class = c("pin",
"character"))) : 
  arguments imply differing number of rows: 2, 1



As a big fan of your work, I know your arguments against R?s recycling
rules (and I do agree) but I would like to allow recycling at least when
(as above) the length of my pin vector is only 1 (I do know of course that
dplyr::data_frame does just that :-).

Best Regards!
Erik B
On 2015-12-08 14:09, "Hadley Wickham" <h.wickham at gmail.com> wrote: