diff --git a/NEWS.md b/NEWS.md index 80a47605..84ff2d3b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ichimoku 1.4.10.9000 (development) +* Arguments 'keep.data' and 'keep.attrs' across the package now have an explicit default value of FALSE (no resultant change in behaviour). + # ichimoku 1.4.10 * Improves handling of OANDA API errors. diff --git a/R/ichimoku.R b/R/ichimoku.R index d4f38679..7c931439 100644 --- a/R/ichimoku.R +++ b/R/ichimoku.R @@ -32,8 +32,8 @@ #' periods used for the cloud. This parameter shoud not normally be modified #' as using other values would be invalid in the context of traditional #' ichimoku analysis. -#' @param keep.data (optional) set to TRUE to retain additional data present -#' in the input object as additional columns and/or attributes. +#' @param keep.data [default FALSE] set to TRUE to retain additional data +#' present in the input object as additional columns and/or attributes. #' @param ... additional arguments, for instance 'holidays', passed along to #' \code{\link{tradingDays}} for calculating the future cloud on daily data. @@ -110,18 +110,18 @@ #' @rdname ichimoku #' @export #' -ichimoku <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) UseMethod("ichimoku") +ichimoku <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) UseMethod("ichimoku") #' @rdname ichimoku #' @method ichimoku ichimoku #' @export #' -ichimoku.ichimoku <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) { +ichimoku.ichimoku <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) { if (missing(ticker)) ticker <- attr(x, "ticker") x <- x[!is.na(coredata.ichimoku(x)[, "close"]), ] - if (!missing(keep.data) && isTRUE(keep.data)) { + if (isTRUE(keep.data)) { x$cd <- x$tenkan <- x$kijun <- x$senkouA <- x$senkouB <- x$chikou <- x$cloudT <- x$cloudB <- NULL x <- as.data.frame.ichimoku(x, keep.attrs = TRUE) } else { @@ -136,10 +136,10 @@ ichimoku.ichimoku <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, . #' @method ichimoku xts #' @export #' -ichimoku.xts <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) { +ichimoku.xts <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) { if (missing(ticker)) ticker <- deparse(substitute(x)) - x <- xts_df(x, keep.attrs = !missing(keep.data) && isTRUE(keep.data)) + x <- xts_df(x, keep.attrs = isTRUE(keep.data)) ichimoku.data.frame(x, ticker = ticker, periods = periods, keep.data = keep.data, ...) @@ -149,7 +149,7 @@ ichimoku.xts <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) { #' @method ichimoku data.frame #' @export #' -ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) { +ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) { if (missing(ticker)) ticker <- deparse(substitute(x), width.cutoff = 500L, backtick = FALSE, control = NULL, nlines = 1L) xlen <- dim(x)[1L] @@ -238,15 +238,15 @@ ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, } xtsindex <- c(index, future) - if (missing(keep.data) || !isTRUE(keep.data)) { - x <- kmatrix <- NULL - } else { + if (isTRUE(keep.data)) { used <- unlist(lapply(c("coli", "colo", "colh", "coll", "colc", "colp"), function(x) get0(x, envir = parent.frame(2L), inherits = FALSE))) used <- used[!is.na(used)] keep <- if (!is.null(used)) cnames[-used] kmatrix <- do.call(cbind, lapply(.subset(x, keep), function(x) `length<-`(as.numeric(x), clen))) + } else { + x <- kmatrix <- NULL } kumo <- cbind(open = `length<-`(open, clen), @@ -271,10 +271,10 @@ ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, #' @method ichimoku matrix #' @export #' -ichimoku.matrix <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) { +ichimoku.matrix <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) { if (missing(ticker)) ticker <- deparse(substitute(x), width.cutoff = 500L, backtick = FALSE, control = NULL, nlines = 1L) - x <- matrix_df(x, keep.attrs = !missing(keep.data) && isTRUE(keep.data)) + x <- matrix_df(x, keep.attrs = isTRUE(keep.data)) ichimoku.data.frame(x, ticker = ticker, periods = periods, keep.data = keep.data, ...) @@ -284,7 +284,7 @@ ichimoku.matrix <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ... #' @method ichimoku default #' @export #' -ichimoku.default <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) { +ichimoku.default <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) { is.character(x) || stop("cannot create an ichimoku object from a '", class(x)[1L], "' object", call. = FALSE) exists(x) || stop("object '", x, "' not found", call. = FALSE) diff --git a/R/methods.R b/R/methods.R index a3c18392..97569a59 100644 --- a/R/methods.R +++ b/R/methods.R @@ -205,7 +205,7 @@ summary.ichimoku <- function(object, strat = TRUE, ...) { #' @param x an object of class 'ichimoku'. #' @param row.names not used. #' @param optional not used. -#' @param keep.attrs (optional) if set to TRUE, will preserve any custom +#' @param keep.attrs [default FALSE] if set to TRUE, will preserve any custom #' attributes set on the original object. #' @param ... arguments passed to or from other methods. #' @@ -227,8 +227,8 @@ summary.ichimoku <- function(object, strat = TRUE, ...) { #' @method as.data.frame ichimoku #' @export #' -as.data.frame.ichimoku <- function(x, row.names, optional, keep.attrs, ...) - .Call(ichimoku_tbl, x, !missing(keep.attrs) && isTRUE(keep.attrs)) +as.data.frame.ichimoku <- function(x, row.names, optional, keep.attrs = FALSE, ...) + .Call(ichimoku_tbl, x, isTRUE(keep.attrs)) #' @name coredata #' @rdname coredata.ichimoku diff --git a/R/utils.R b/R/utils.R index 1cd42ff0..6a5ca1ed 100644 --- a/R/utils.R +++ b/R/utils.R @@ -103,7 +103,7 @@ grid_dup <- function(n, omit.id) { #' An optimised 'xts' to 'data.frame' constructor. #' #' @param x an 'xts' object. -#' @param keep.attrs (optional) if set to TRUE, will preserve any custom +#' @param keep.attrs [default FALSE] if set to TRUE, will preserve any custom #' attributes set on the original object. #' #' @return A 'data.frame' object. The 'xts' index is preserved as the first @@ -123,7 +123,7 @@ grid_dup <- function(n, omit.id) { #' #' @export #' -xts_df <- function(x, keep.attrs) { +xts_df <- function(x, keep.attrs = FALSE) { core <- coredata(x) dn2 <- dimnames(core)[[2L]] xlen <- dim(core)[1L] @@ -139,7 +139,7 @@ xts_df <- function(x, keep.attrs) { `attributes<-`(df, c(list(names = c("index", dn2), class = "data.frame", row.names = .set_row_names(xlen)), - if (!missing(keep.attrs) && isTRUE(keep.attrs)) + if (isTRUE(keep.attrs)) .Call(ichimoku_look, x))) } @@ -148,7 +148,7 @@ xts_df <- function(x, keep.attrs) { #' An optimised 'matrix' to 'data.frame' constructor. #' #' @param x a matrix. -#' @param keep.attrs (optional) if set to TRUE, will preserve any custom +#' @param keep.attrs [default FALSE] if set to TRUE, will preserve any custom #' attributes set on the original object. #' #' @return A 'data.frame' object. If the matrix has row names, these are @@ -167,8 +167,8 @@ xts_df <- function(x, keep.attrs) { #' #' @export #' -matrix_df <- function(x, keep.attrs) { - lk <- if (!missing(keep.attrs) && isTRUE(keep.attrs)) .Call(ichimoku_look, x) +matrix_df <- function(x, keep.attrs = FALSE) { + lk <- if (isTRUE(keep.attrs)) .Call(ichimoku_look, x) dn <- dimnames(x) xlen <- dim(x)[1L] len <- dim(x)[2L] diff --git a/man/as.data.frame.ichimoku.Rd b/man/as.data.frame.ichimoku.Rd index 93633246..3881f6e8 100644 --- a/man/as.data.frame.ichimoku.Rd +++ b/man/as.data.frame.ichimoku.Rd @@ -4,7 +4,7 @@ \alias{as.data.frame.ichimoku} \title{Convert ichimoku to data.frame} \usage{ -\method{as.data.frame}{ichimoku}(x, row.names, optional, keep.attrs, ...) +\method{as.data.frame}{ichimoku}(x, row.names, optional, keep.attrs = FALSE, ...) } \arguments{ \item{x}{an object of class 'ichimoku'.} @@ -13,7 +13,7 @@ \item{optional}{not used.} -\item{keep.attrs}{(optional) if set to TRUE, will preserve any custom +\item{keep.attrs}{[default FALSE] if set to TRUE, will preserve any custom attributes set on the original object.} \item{...}{arguments passed to or from other methods.} diff --git a/man/ichimoku.Rd b/man/ichimoku.Rd index 5f2507ea..9a75d93c 100644 --- a/man/ichimoku.Rd +++ b/man/ichimoku.Rd @@ -9,17 +9,17 @@ \alias{ichimoku.default} \title{ichimoku} \usage{ -ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) +ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) -\method{ichimoku}{ichimoku}(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) +\method{ichimoku}{ichimoku}(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) -\method{ichimoku}{xts}(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) +\method{ichimoku}{xts}(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) -\method{ichimoku}{data.frame}(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) +\method{ichimoku}{data.frame}(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) -\method{ichimoku}{matrix}(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) +\method{ichimoku}{matrix}(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) -\method{ichimoku}{default}(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...) +\method{ichimoku}{default}(x, ticker, periods = c(9L, 26L, 52L), keep.data = FALSE, ...) } \arguments{ \item{x}{a data.frame or other compatible object, which includes xts, @@ -33,8 +33,8 @@ periods used for the cloud. This parameter shoud not normally be modified as using other values would be invalid in the context of traditional ichimoku analysis.} -\item{keep.data}{(optional) set to TRUE to retain additional data present -in the input object as additional columns and/or attributes.} +\item{keep.data}{[default FALSE] set to TRUE to retain additional data +present in the input object as additional columns and/or attributes.} \item{...}{additional arguments, for instance 'holidays', passed along to \code{\link{tradingDays}} for calculating the future cloud on daily data.} diff --git a/man/matrix_df.Rd b/man/matrix_df.Rd index cf2869d9..1bbac423 100644 --- a/man/matrix_df.Rd +++ b/man/matrix_df.Rd @@ -4,12 +4,12 @@ \alias{matrix_df} \title{Convert matrix to data.frame} \usage{ -matrix_df(x, keep.attrs) +matrix_df(x, keep.attrs = FALSE) } \arguments{ \item{x}{a matrix.} -\item{keep.attrs}{(optional) if set to TRUE, will preserve any custom +\item{keep.attrs}{[default FALSE] if set to TRUE, will preserve any custom attributes set on the original object.} } \value{ diff --git a/man/xts_df.Rd b/man/xts_df.Rd index 0ff40d22..c9d3f95d 100644 --- a/man/xts_df.Rd +++ b/man/xts_df.Rd @@ -4,12 +4,12 @@ \alias{xts_df} \title{Convert xts to data.frame} \usage{ -xts_df(x, keep.attrs) +xts_df(x, keep.attrs = FALSE) } \arguments{ \item{x}{an 'xts' object.} -\item{keep.attrs}{(optional) if set to TRUE, will preserve any custom +\item{keep.attrs}{[default FALSE] if set to TRUE, will preserve any custom attributes set on the original object.} } \value{