1

I am simply trying to limit the decimals for my output. But the digits argument is giving me trouble.

My code

#' @export
print.xts <- function(x) {
  print(x, digits = 5)

}

Gives the error when printing an xts object

Error in print.xts(x, digits = 5) : unused argument (digits = 5) 

What can be the issue?

Stedy
  • 7,359
  • 14
  • 57
  • 77
uncool
  • 2,613
  • 7
  • 26
  • 55
  • Have you tried `options()`? – Stedy Dec 23 '15 at 15:33
  • 1
    Maybe it's because there's already a `print.xts` when you load the "xts" package. Have you tried giving "x" a different class and renaming your `print.xts` to whatever that class is? – A5C1D2H2I1M1N2O1R2T1 Dec 23 '15 at 15:33
  • Ahh, smart @AnandaMahto. That shold be it. So basically I was referencing in a loop...But shouldn't my print.xts override the print.xts in the xts package? – uncool Dec 23 '15 at 15:35
  • Can't you use `digits` with the default `print.xts` method? – A5C1D2H2I1M1N2O1R2T1 Dec 23 '15 at 15:35
  • Is there a way to set the digits option for xts print.xts? I found it at http://stackoverflow.com/questions/2287616/controlling-number-of-decimal-digits-in-print-output-in-r – uncool Dec 23 '15 at 15:36
  • 1
    @uncool, `print(sample.xts, digits = 2)` gives me the results with 2 digits ("sample.xts" comes from the help page for `xts`). – A5C1D2H2I1M1N2O1R2T1 Dec 23 '15 at 15:42
  • Yes. Thank you @AnandaMahto. What I essentially was trying to do was to override the print.xts function. But I've gone with the solution to change the options(digits = ) instead. – uncool Dec 23 '15 at 15:43

1 Answers1

1

There already exists a print.xts method in the xts package, try renaming the function which should work.

JCollerton
  • 3,227
  • 2
  • 20
  • 25