[R] limited formula length in tsls

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Aug 23 12:34:58 CEST 2001


On Thu, 23 Aug 2001, Zsombor Cseres-Gergely wrote:

> On Thu, Aug 23, 2001 at 07:53:59AM +0100, Prof Brian D Ripley wrote:
> >
> > The `tsls package' had me confused ...
>
> Sorry about this.
>
> > > The reason that the original version manipulates (somewhat awkwardly) the
> > > model and instrumental-variables formulas in character form to produce a
> > > combined formula to insure that missing data is treated consistently
>
> So I guess the answer to my other question (what is the problem with my
> workaround?) is that it does not comply with this requirement.
>
>
> [snip]
>
>
> > as.character is not the best tool for formulae.  Use deparse:
> >
> > > deparse(mod)
> > [1] "this ~ is + a + very + long + formula + with + a + very + large + "
> > [2] "    number + of + characters"
> >
> > say via
> >
> > paste(deparse(mod, 500), collapse="")
> >
> > which will cope with arbitrary long formulae.
>
> That is true but returns a string. The procedure, however wants to make use
> of the structure that is returned by as.character (or paste, through the former)
> when applied to a formula: [1] is tilde [2] is response [3] is covariates. If
> I use paste(deparse(...) ...) the structure is lost. I could probably get it
> back (do not know, how), but that sounds like reinventing the wheel. I tried
> to figure out, who does the magic: printing just the argument results a string,
> but after using as.character, the structure appears. Looking at the C source,
> I got lost, I must admit.

If you want the rhs, paste(deparse(mod[[3]], 500), collapse="") is what
you want.  Do using indexing on the object itself, not on some dump of it.

> > The cutoff limit is 500, and a trivial change to the internals of
> > as.character (which I have just made for 1.3.1) increases the cutoff from
> > 60 to 500. Nevertheless. paste(deparse(mod, 500), collapse="") remains
> > better.
>
> Is in necessary to have an arbitrary limit? I do not know anything about C
> (or any) programming, but the Hurd (for example) runs without a maximal path-
> name length defined and R conformes to this.

No, and you could write a patch to remove the limit ....
It's much easier to have simple limits, and the tools that the cognescenti
would use here do work without limits.

For what it is worth, S would give you

[1] " ~ "
[2] "this"
[3] "is + a + very + long + formula + with + a + very + large + number +
of + \n\tcharacters"

which is reasonable, but not what you wanted.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list