robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.11k stars 341 forks source link

could not find function "Acf" #896

Closed AlissonRP closed 2 years ago

AlissonRP commented 2 years ago

I'm trying to run forecast::ggAcf(rnorm(100))

forecast::ggAcf(rnorm(100))
Error in Acf(x = rnorm(100), plot = FALSE) : 
  could not find function "Acf"

but ggAcf has dependency on Acf and autoplot, but AcF is in the forecast namespace, and since I didn't give library/require, ggAcf can't find this function (I'm not giving library/require because it doesn't I need all of the forecast functions), since your package has a dependency on ggplot2 wouldn't it be interesting to write ggAcf that way?

ggAcf <- function(x, lag.max = NULL,
                  type = c("correlation", "covariance", "partial"),
                  plot = TRUE, na.action = na.contiguous, demean=TRUE, ...) {
  cl <- match.call()
  if (plot) {
    cl$plot <- FALSE
  }
  cl[[1]] <- quote(forecast::Acf)
  object <- eval.parent(cl)
  object$tsp <- tsp(x)
  object$periods <- attributes(x)$msts
  if (plot) {
    return(ggplot2::autoplot(object, ...))
  }
  else {
    return(object)
  }
}

ggAcf(rnorm(100))

Rplot

mitchelloharawild commented 2 years ago

Fixed in 432d6a1125a9c481231a042de7c2d76bc95aa84a

forecast::ggAcf(rnorm(100))
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

forecast::ggPacf(rnorm(100))

forecast::ggCcf(rnorm(100),rnorm(100))

Created on 2021-12-06 by the reprex package (v2.0.0)