Second & subsequent calls to function fails. Please help debug.
On 29/03/2008 9:47 PM, Michael Kubovy wrote:
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?
________
I don't see anything obvious, so I guess it's the usual advice: Use traceback() to see what function was trying to do the parsing. Debug that function, and see why it was trying to parse that string. If that doesn't make it obvious, put together a minimal reproducible version that others can try, and see if anyone else can spot the problem. Duncan Murdoch