Skip to content

Commit

Permalink
Order columns before adding Symbol to colnames
Browse files Browse the repository at this point in the history
Calling OHLCV() on an object that has the ticker "LOW*" results in all
columns being included where only the "LOW.Low" column should be. This
is because all columns match the pattern, "low". This is similar to
issue #24.

Work-around the issue by ordering the columns via OHLCV() _before_
appending the symbol to the column names.

Also put any adjusted columns in the right-most positions.

Fixes #259.
  • Loading branch information
joshuaulrich committed Nov 15, 2018
1 parent bd675f7 commit 9f97eb5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/getSymbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -1447,12 +1447,21 @@ getSymbols.tiingo <- function(Symbols, env, api.key,
}
tm.stamps <- as.POSIXct(stock.data[, "date"], ...)
stock.data[, "date"] <- NULL

# adjusted column names
adjcols <- grepl("^adj", colnames(stock.data))
# order Tiingo column names before converting to quantmod names
stock.data <- OHLCV(stock.data)
if (any(adjcols)) {
# put adjusted columns last
stock.data <- stock.data[, c(which(!adjcols), which(adjcols))]
}
# now convert to quantmod column names
colnames(stock.data) <- qm.names[match(colnames(stock.data), tiingo.names)]

# convert data to xts
xts.data <- xts(stock.data, tm.stamps, src="tiingo", updated=Sys.time())
xts.data <- convert.time.series(xts.data, return.class=return.class)
# order columns
xts.data <- OHLCV(xts.data)
if (auto.assign)
assign(sym, xts.data, env)
return(xts.data)
Expand Down

0 comments on commit 9f97eb5

Please sign in to comment.