Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Print trailing zeros for index with fractional seconds #404

Closed
joshuaulrich opened this issue Sep 6, 2023 · 0 comments
Closed

Print trailing zeros for index with fractional seconds #404

joshuaulrich opened this issue Sep 6, 2023 · 0 comments
Assignees
Labels
Milestone

Comments

@joshuaulrich
Copy link
Owner

joshuaulrich commented Sep 6, 2023

An object with an index that has sub-millisecond resolution may not print with the same number of decimal places for every index value. This is due to using as.character() instead of format().

library(xts)
set.seed(21)
n <- 1000
x <- .xts(rnorm(n), seq(1, n^2, n) + rnorm(n), dimnames = list(NULL, "x"))
print(x)
##                                      x
## 1969-12-31 18:00:01.793013  0.09516123
## 1969-12-31 18:16:41.522251 -0.03745645
## 1969-12-31 18:33:22.746222  0.92128291
## 1969-12-31 18:49:59.728664  1.66030628
##  1969-12-31 19:06:43.19739  0.79644836
## 1969-12-31 19:23:21.433131 -0.30404359
##   1969-12-31 19:39:59.4298 -1.43072982
## 1969-12-31 19:56:40.065094 -1.49423665
## 1969-12-31 20:13:21.063493  1.28826724
## 1969-12-31 20:30:00.997607 -0.48998283
##                        ...            
## 1970-01-12 05:00:00.809472  0.73573729
## 1970-01-12 05:16:39.574975 -2.49222511
## 1970-01-12 05:33:20.727859 -0.15759198
## 1970-01-12 05:50:01.061682  0.08606529
## 1970-01-12 06:06:41.125089  0.05555260
## 1970-01-12 06:23:20.961295 -1.27153534
## 1970-01-12 06:40:00.341953 -0.29615803
## 1970-01-12 06:56:40.378155 -0.37328966
##  1970-01-12 07:13:22.48765 -0.64532629
## 1970-01-12 07:30:01.368432 -0.37238591

# a more extreme example
y <- .xts(1:10, .POSIXct(c(1.0001, 2.002, 3.03, 4:9, 10.000001)),
          dimnames = list(NULL, "x"))
print(y, show.rows = 3, max.rows = 5)
##                             x
##   1969-12-31 18:00:01.0001  1
##    1969-12-31 18:00:02.002  2
##     1969-12-31 18:00:03.03  3
##                        ...   
##        1969-12-31 18:00:08  8
##        1969-12-31 18:00:09  9
## 1969-12-31 18:00:10.000001 10
@joshuaulrich joshuaulrich self-assigned this Sep 6, 2023
@joshuaulrich joshuaulrich added this to the 0.13.2 milestone Nov 17, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 24, 2024
# xts 0.14.x (202x-xx-xx)

* `plot.xts()` now renders all panels when 'x' has more than 8 columns and
  `multi.panel = TRUE`. Columns 9 and later didn't render because the default
  of `plot.xts()` is 'col = 1:8'. Thanks to Ethan Smith for the report and
  patch.
  ([#423](joshuaulrich/xts#423))
  ([#424](joshuaulrich/xts#424))

* `plot.xts()` no longer errors when 'ylim' is constant and negative. Thanks
  to Ethan Smith for the report.
  ([#422](joshuaulrich/xts#422))

* Do not use `SET_TYPEOF()` in C because it is not part of the public R API.

* `merge.xts()` no longer converts 'x' or 'y' from double to integer in the C
  code when they are not used in the result. This avoids an unnecessary and
  confusing warning. Thanks to Jeff Ryan for the report.

# xts 0.14.0 (2024-06-05)

* `addEventLines()` and `addLegend()` now draw on multiple panels when `on` is
  a vector. Thanks to Ethan Smith for the report.
  ([#420](joshuaulrich/xts#420))

* Replace `SET_TYPEOF()` in merge.c because it will error when it tries to
  convert a REAL to an INTEGER. Thanks to Kurt Hornik for the report!
  ([#419](joshuaulrich/xts#419))

* Fix crash when 'j' is not an integer and in [0, 1) (e.g. `j = 0.1`). Also
  throw a warning when 'j' is not an integer.
  ([#413](joshuaulrich/xts#413))
  ([#415](joshuaulrich/xts#415))

* Fix plot header when `layout()` is used to draw multiple plots on a single
  device. Thanks to Dirk Eddelbuettel for the report and testing!
  ([#412](joshuaulrich/xts#412))

* Fix plot legend location when the y-axis is log scale.
  ([#407](joshuaulrich/xts#407))

# xts 0.13.2 (2024-01-21)

* Print a message when `period.apply()` is called with `FUN = mean` because it
  calculates the mean for each column, not all the data in the subset like it
  does for all other functions. The message says to use `FUN = colMeans` for
  current behavior and `FUN = function(x) mean(x)` to calculate the mean for
  all the data. This information is also included in the help files. The option
  `xts.message.period.apply.mean = FALSE` suppresses the message.
  ([#124](joshuaulrich/xts#124))

* Fix error when `print.xts()` is called 'quote' or 'right' arguments.
  ([#401](joshuaulrich/xts#401))

* Fix `addPolygon()` so it renders when `observation.based = TRUE`.
  ([#403](joshuaulrich/xts#403))

* Print trailing zeros for index value with fractional seconds, so every index
  value has the same number of characters.
  ([#404](joshuaulrich/xts#404))

* Add ability to log scale the y-axis in `plot.xts()`.
  ([#103](joshuaulrich/xts#103))

* Actually change the underlying index values when 'tclass' is changed from a
  class with a timezone (e.g. POSIXct) to one without a timezone (e.g. Date).
  Add a warning when this happens, with a global option to always suppress the
  warning.
  ([#311](joshuaulrich/xts#311)).

* Significantly refactor the internals of `plot.xts()`.
  ([#408](joshuaulrich/xts#408))
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant