Skip to content

as.character limits length of result for formula

2 messages · Terrence Ireland, William Dunlap

#
as.character() doesn't give a faithful character
representation of its input for lots of language-
related inputs.  E.g.,
  > f <- reformulate(paste(sep="","X",1:500), quote(log(Y)))
  > cat(strwrap(as.character(f), 60), sep="\n")
  ~
  log(Y)
  X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11 +
  X12 + X13 + X14 + X15 + X16 + X17 + X18 + X19 + X20 + X21 +
  X22 + X23 + X24 + X25 + X26 + X27 + X28 + X29 + X30 + X31 +
  X32 + X33 + X34 + X35 + X36 + X37 + X38 + X39 + X40 + X41 +
  X42 + X43 + X44 + X45 + X46 + X47 + X48 + X49 + X50 + X51 +
  X52 + X53 + X54 + X55 + X56 + X57 + X58 + X59 + X60 + X61 +
  X62 + X63 + X64 + X65 + X66 + X67 + X68 + X69 + X70 + X71 +
  X72 + X73 + X74 + X75 + X76 + X77 + X78 + X79 + X80 + X81 +
  X82 + X83 + X84 + X85 +
(Yes, there is nothing after the "X85 +".)

deparse() works better for such objects.  You may want to use
paste(collapse="\n") on its output to make a single string.
  > deparse(f)
   [1] "log(Y) ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11
+ " 
   [2] "    X12 + X13 + X14 + X15 + X16 + X17 + X18 + X19 + X20 + X21 +
"   
   ... lots of text omitted ...
  [53] "    X480 + X481 + X482 + X483 + X484 + X485 + X486 + X487 + X488
+ "
  [54] "    X489 + X490 + X491 + X492 + X493 + X494 + X495 + X496 + X497
+ "
  [55] "    X498 + X499 + X500"     


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com