[R] Second & subsequent calls to function fails. Please help debug.

From: Michael Kubovy <kubovy_at_virginia.edu>
Date: Sat, 29 Mar 2008 21:47:02 -0400


Dear R-helpers,

I'm running Sweave() on a file. First run:
> Sweave('20080331.Rnw')

Writing to file 20080331.tex
Processing code chunks ...

  1 : term hide (label=setup)
  2 : echo term verbatim (label=oatvar)
  3 : echo term verbatim (label=oatvar1)
  4 : echo term verbatim (label=oat2wt)
  5 : echo term verbatim (label=oat2wt)
  6 : echo term verbatim (label=lm)
  7 : echo term verbatim (label=diag)
  8 : echo term verbatim (label=tukey)
  9 : echo term verbatim (label=efficiency)
10 : echo term verbatim (label=wear)

11 : echo term verbatim (label=wearX)
12 : echo term verbatim (label=gyd)
Loading required package: crossdes
Loading required package: AlgDesign
Loading required package: gtools

Attaching package: 'gtools'

        The following object(s) are masked from package:faraway :

         logit

Loading required package: MASS

13 : echo term verbatim (label=2wt)
14 : echo term verbatim (label=ablm)
15 : echo term verbatim (label=abaov)

You can now run LaTeX on '20080331.tex'
There were 42 warnings (use warnings() to see them)

Second run:
> Sweave('20080331.Rnw')

Writing to file 20080331.tex
Processing code chunks ...

  1 : term hide (label=setup)
  2 : echo term verbatim (label=oatvar)
  3 : echo term verbatim (label=oatvar1)
  4 : echo term verbatim (label=oat2wt)
  5 : echo term verbatim (label=oat2wt)
  6 : echo term verbatim (label=lm)
  7 : echo term verbatim (label=diag)
  8 : echo term verbatim (label=tukey)

Error: chunk 8 (label=tukey)
Error in parse(text = x) :

   unexpected symbol in "yield ~ variety + block + preds(yield+variety +block+preds.sq)sq"

It failed in:

<<tukey>>=
require(alr3)
tukey.nonadd.test(ov.lm)
@

At that point I ran debug() on the call: debug(tukey.nonadd.test)
tukey.nonadd.test(ov.lm)
debugging in: tukey.nonadd.test(ov.lm1)
debug: {

     envir <- environment(formula(m))
     dd <- eval(m$call$data, envir)
     subs <- eval(m$call$subset, envir)
     wgts <- eval(m$call$weights, envir)
     naa <- m$call$na.action
     dd <- data.frame(dd, preds.sq = predict(m, dd)^2)
     uf <- update.formula(formula(m$terms), ~. + preds.sq)
     environment(uf) <- environment(NULL)
     mup <- if (is.null(naa))
         lm(uf, data = dd, subset = subs, weights = wgts)
     else lm(uf, data = dd, subset = subs, weights = wgts, na.action =  
naa)
     if (mup$rank > m$rank) {
         ans <- summary(mup)$coef[, 3:4]
         ans <- ans[match("preds.sq", rownames(ans)), ]
         ans[2] <- pnorm(-abs(ans[1])) * 2
         ans
     }
     else c(NA, NA)

}
Browse[1]>
debug: envir <- environment(formula(m))
Browse[1]>
debug: dd <- eval(m$call$data, envir)
Browse[1]>
debug: subs <- eval(m$call$subset, envir) Browse[1]>
debug: wgts <- eval(m$call$weights, envir) Browse[1]>
debug: naa <- m$call$na.action
Browse[1]>
debug: dd <- data.frame(dd, preds.sq = predict(m, dd)^2) Browse[1]>
debug: uf <- update.formula(formula(m$terms), ~. + preds.sq) Browse[1]>
debug: environment(uf) <- environment(NULL) Browse[1]>
debug: mup <- if (is.null(naa)) lm(uf, data = dd, subset = subs, weights = wgts) else lm(uf,

     data = dd, subset = subs, weights = wgts, na.action = naa) Browse[1]>
Error in parse(text = x) :

   unexpected symbol in "yield ~ variety + preds(yield+variety +preds.sq)sq"

Advice?



Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
         McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766

WWW: http://www.people.virginia.edu/~mk9y/

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 30 Mar 2008 - 01:49:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Mar 2008 - 09:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive