From 4c0deefe5891120883df4c3aa39b5df1a94df842 Mon Sep 17 00:00:00 2001 From: Joshua Ulrich Date: Sat, 11 Dec 2021 15:42:19 -0600 Subject: [PATCH] Do not pass a data.frame to checkEqualsNumeric MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(, mode="list"). This will break code relying on 'as.vector()' 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. --- inst/unitTests/runit.TTR.Volatility.R | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/inst/unitTests/runit.TTR.Volatility.R b/inst/unitTests/runit.TTR.Volatility.R index 0798c32..e2c81fc 100644 --- a/inst/unitTests/runit.TTR.Volatility.R +++ b/inst/unitTests/runit.TTR.Volatility.R @@ -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