Skip to content

Commit

Permalink
Do not pass a data.frame to checkEqualsNumeric
Browse files Browse the repository at this point in the history
checkEqualsNumeric() calls as.vector() on the 'current' and 'target'
inputs. R-devel introduced an as.vector.data.frame() method, with the
following entry in the NEWS file:

  * as.vector() gains a data.frame method which returns a simple
    named list, also obeying a long standing ‘FIXME’ to enable
    as.vector(<data.frame>, mode="list"). This will break code relying
    on 'as.vector(<data.frame>)' to return the unchanged data frame.

R <= 4.1.x returns the data frame unchanged, but R-devel now returns a
regular list with names corresponding to the data frame column names.
  • Loading branch information
joshuaulrich committed Dec 11, 2021
1 parent 01b04c6 commit 4c0deef
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions inst/unitTests/runit.TTR.Volatility.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,26 @@ test.Close <- function() {

# Garman Klass
test.garman.klass <- function() {
checkEqualsNumeric( volatility(input$all[,c('Open','High','Low','Close')],calc='garman.klass'), output$allGK )
checkEqualsNumeric( volatility(input$top[,c('Open','High','Low','Close')],calc='garman.klass'), output$topGK )
checkException( volatility(input$mid[,c('Open','High','Low','Close')],calc='garman.klass') )
ohlc <- c('Open','High','Low','Close')
checkEqualsNumeric( volatility(input$all[,ohlc],calc='garman.klass')[["x"]], output$allGK[["x"]] )
checkEqualsNumeric( volatility(input$top[,ohlc],calc='garman.klass')[["x"]], output$topGK[["x"]] )
checkException( volatility(input$mid[,ohlc],calc='garman.klass') )
}

# Parkinson
test.parkinson <- function() {
checkEqualsNumeric( volatility(input$all[,c('Open','High','Low','Close')],calc='parkinson'), output$allParkinson )
checkEqualsNumeric( volatility(input$top[,c('Open','High','Low','Close')],calc='parkinson'), output$topParkinson )
checkException( volatility(input$mid[,c('Open','High','Low','Close')],calc='parkinson') )
ohlc <- c('Open','High','Low','Close')
checkEqualsNumeric( volatility(input$all[,ohlc],calc='parkinson')[["x"]], output$allParkinson[["x"]] )
checkEqualsNumeric( volatility(input$top[,ohlc],calc='parkinson')[["x"]], output$topParkinson[["x"]] )
checkException( volatility(input$mid[,ohlc],calc='parkinson') )
}

# Rogers Satchell
test.rogers.satchell <- function() {
checkEqualsNumeric( volatility(input$all[,c('Open','High','Low','Close')],calc='rogers.satchell'), output$allRS )
checkEqualsNumeric( volatility(input$top[,c('Open','High','Low','Close')],calc='rogers.satchell'), output$topRS )
checkException( volatility(input$mid[,c('Open','High','Low','Close')],calc='rogers.satchell') )
ohlc <- c('Open','High','Low','Close')
checkEqualsNumeric( volatility(input$all[,ohlc],calc='rogers.satchell')[["x"]], output$allRS[["x"]] )
checkEqualsNumeric( volatility(input$top[,ohlc],calc='rogers.satchell')[["x"]], output$topRS[["x"]] )
checkException( volatility(input$mid[,ohlc],calc='rogers.satchell') )
}

# Chaikin Volatility
Expand Down

0 comments on commit 4c0deef

Please sign in to comment.