Skip to content

Is this a bug in quantmod::OpCl?

2 messages · James Hirschorn, Joshua Ulrich

#
OpCl works on xts objects but not on quantmod.OHLC objects. Is this a bug?

Example error:

x.Date <- as.Date("2003-02-01") + c(1, 3, 7, 9, 14) - 1
set.seed(1)
x <- zoo(matrix(runif(20, 0, 1), nrow=5, ncol=4), x.Date)
q <- as.quantmod.OHLC(x,c("Open","High","Low","Close"))

# error
OpCl(q)
#> Error in `colnames<-`(`*tmp*`, value = "OpCl.q") : 
#>  attempt to set 'colnames' on an object with less than two dimensions

# OK
OpCl(as.xts(q))
#
On Tue, Apr 5, 2016 at 9:17 PM, James Hirschorn
<james.hirschorn at hotmail.com> wrote:
Thanks for the minimal, reproducible example.

Looks like a bug.  There's no as.quantmod.OHLC.xts method, so the zoo
method is dispatched.  Calling Op() or Cl() on this zoo-based object
results in a vector (since zoo will drop dimensions, like a matrix or
data.frame), and you can't set column names on a vector.

I'm not sure whether it makes more sense to check for dims in all the
combination transformations (consisting of combined Op, Hi, Lo, Cl) or
to create a as.quantmod.OHLC.xts method.

Can you provide some details about your use case?