|
1 | | -# Copyright (C) 2021-2023 Hibiki AI Limited <info@hibiki-ai.com> |
| 1 | +# Copyright (C) 2021-2025 Hibiki AI Limited <info@hibiki-ai.com> |
2 | 2 | # |
3 | 3 | # This file is part of ichimoku. |
4 | 4 | # |
@@ -85,10 +85,10 @@ str.ichimoku <- function(object, ...) { |
85 | 85 | dims <- attr(object, "dim") |
86 | 86 | if (is.null(dims)) { |
87 | 87 | xlen <- length(object) |
88 | | - dates <- format.POSIXct(index.ichimoku(object, c(1L, xlen))) |
| 88 | + dates <- format_POSIXct(index.ichimoku(object, c(1L, xlen))) |
89 | 89 | cat("ichimoku object with no dimensions\nVector <numeric> w/ length:", xlen, file = stdout()) |
90 | 90 | } else { |
91 | | - dates <- format.POSIXct(index.ichimoku(object, c(1L, dims[1L]))) |
| 91 | + dates <- format_POSIXct(index.ichimoku(object, c(1L, dims[1L]))) |
92 | 92 | cat("ichimoku object [", dates[1L], " / ", dates[2L], "] (", |
93 | 93 | dims[1L], ", ", dims[2L], ")", if (hasStrat(object)) " w/ strat", |
94 | 94 | "\n <double> $", file = stdout(), sep = "") |
@@ -171,7 +171,7 @@ summary.ichimoku <- function(object, strat = TRUE, ...) { |
171 | 171 | end <- sum(!is.na(core[, "close"])) |
172 | 172 | high <- which.max(core[1:end, "high"]) |
173 | 173 | low <- which.min(core[1:end, "low"]) |
174 | | - dates <- format.POSIXct(index.ichimoku(object, c(1L, high, low, end))) |
| 174 | + dates <- format_POSIXct(index.ichimoku(object, c(1L, high, low, end))) |
175 | 175 | cat("\n Max: ", dates[2L], " [", core[high, "high"], |
176 | 176 | "]\nStart: ", dates[1L], " [", core[1L, "open"], |
177 | 177 | "] End: ", dates[4L], " [", core[end, "close"], |
@@ -262,20 +262,23 @@ NULL |
262 | 262 | #' @method coredata ichimoku |
263 | 263 | #' @export |
264 | 264 | #' |
265 | | -coredata.ichimoku <- function(x, fmt, ...) |
266 | | - if (missing(fmt)) |
267 | | - .Call(ichimoku_coredata, x) else if (is.null(attr(x, "dim"))) |
268 | | - `attributes<-`( |
269 | | - x, |
270 | | - list(names = if (is.character(fmt)) format.POSIXct(index.ichimoku(x), format = fmt) else |
271 | | - format.POSIXct(index.ichimoku(x))) |
272 | | - ) else |
273 | | - `attributes<-`( |
274 | | - x, |
275 | | - list(dim = attr(x, "dim"), |
276 | | - dimnames = list(if (is.character(fmt)) format.POSIXct(index.ichimoku(x), format = fmt) else |
277 | | - format.POSIXct(index.ichimoku(x)), attr(x, "dimnames")[[2L]])) |
278 | | - ) |
| 265 | +coredata.ichimoku <- function(x, fmt, ...) { |
| 266 | + missing(fmt) && return(.Call(ichimoku_coredata, x)) |
| 267 | + if (is.null(attr(x, "dim"))) { |
| 268 | + `attributes<-`( |
| 269 | + x, |
| 270 | + list(names = if (is.character(fmt)) format.POSIXct(index.ichimoku(x), format = fmt) else |
| 271 | + format_POSIXct(index.ichimoku(x))) |
| 272 | + ) |
| 273 | + } else { |
| 274 | + `attributes<-`( |
| 275 | + x, |
| 276 | + list(dim = attr(x, "dim"), |
| 277 | + dimnames = list(if (is.character(fmt)) format.POSIXct(index.ichimoku(x), format = fmt) else |
| 278 | + format_POSIXct(index.ichimoku(x)), attr(x, "dimnames")[[2L]])) |
| 279 | + ) |
| 280 | + } |
| 281 | +} |
279 | 282 |
|
280 | 283 | #' @name index |
281 | 284 | #' @rdname index.ichimoku |
|
311 | 314 | #' @method index ichimoku |
312 | 315 | #' @export |
313 | 316 | #' |
314 | | -index.ichimoku <- function(x, subset, ...) |
315 | | - if (missing(subset)) |
316 | | - .Call(ichimoku_index, x) else |
317 | | - .Call(ichimoku_psxct, .subset(attr(x, "index"), subset)) |
| 317 | +index.ichimoku <- function(x, subset, ...) { |
| 318 | + missing(subset) && return(.Call(ichimoku_index, x)) |
| 319 | + .Call(ichimoku_psxct, .subset(attr(x, "index"), subset)) |
| 320 | +} |
0 commit comments