[R] Is this a bug in quantmod::OpCl?

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Apr 7 01:58:49 CEST 2016


On Tue, Apr 5, 2016 at 9:17 PM, James Hirschorn
<james.hirschorn at hotmail.com> wrote:
>
> OpCl works on xts objects but not on quantmod.OHLC objects. Is this a bug?
>
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?

> 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))
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2016 | www.rinfinance.com



More information about the R-help mailing list