[R] Error in curve 'expr' did not evaluate to an object of length 'n'

William Dunlap wdunlap at tibco.com
Mon Mar 6 00:39:33 CET 2017


You define a function called running.acf.max and then call
    plot(running.acf.max)
R's plot, when given a function f, makes a plot of f(x) vs. x
by calling curve().

Did you mean to plot the result of running.acf.max with its
default arguments?  That would be done with
    plot(running.acf.max())

There are several other problems with this code.  E.g., you have
  running.acf.max <-
  function (data = returns, window = 100, nlags = 5, plot = T, main = "")
  {
      clevel <- qnorm(0.5 + 0.95/2)/sqrt(window)
      series <- rollapply(data = returns, window, align = "right",
          by = 1, function(w) {
          ...

You should have data=data in the call to rollapply so it depends
on the 'data' argument to running.acf.max.

Use traceback() after an error to see where the error came from.



Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Mar 3, 2017 at 4:43 AM, Allan Tanaka <allantanaka11 at yahoo.com> wrote:
> Please help. I try to re-produce R-script by plotting a set of functionWhen i running code: plot(Vectorize(running.acf.max))it gets the error message like this: Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,  :   'expr' did not evaluate to an object of length 'n'
> Even though i have vectorized the function argument.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list