0

I am trying to compute an empirical probability distribution for a continuous variable using the epdfPlot() function in the EnvStats:: package. I keep getting an error when I accept the default of discrete=FALSE.

Error in UseMethod("density") : 
  no applicable method for 'density' applied to an object of class "c('double', 'numeric')"

Reading through the documentation, I think this is somehow a result of how the function passes arguments to stats::density() because I don't have this problem when I set discrete = TRUE. As the documentation notes, the argument density.arg.list=NULL is ignored when discrete = TRUE. Here is the reproducible example:

library(EnvStats)

dat<-rnorm(500, 0, 1)
demo1<-epdfPlot(dat, discrete = FALSE, plot.it=FALSE) # throws error
demo2<-epdfPlot(dat, discrete = TRUE, plot.it=FALSE) # works
demo2

Is this possibly a bug?

Sean McKenzie
  • 707
  • 3
  • 13

1 Answers1

0

Turns out this occurs because of a conflict with the labdsv::density() function. EnvStats::epdfPlot() doesn't specify stats::density(), so when density() gets masked by another package, EnvStats::epdfPlot() calls that function. I tried running the code in a different session and it worked without error.

Sean McKenzie
  • 707
  • 3
  • 13