Home > front end >  How to verify symbol value in r testthat?
How to verify symbol value in r testthat?

Time:01-20

What's the correct way of testing equality in a symbol?

I've tried

expect_equal( tsibble::index(bngoRawData), "time" )

but it fails with:

tsibble::index(bngoRawData) (`actual`) not equal to "time" (`expected`).

`actual` is a symbol
`expected` is a character vector ('time')

Without the quotes on "time" it complains its a function instead.

CodePudding user response:

We can use as.name:

library(tsibble)
library(testthat)
expect_equal(tsibble::index(pedestrian), as.name("Date_Time"))

Alternatively we can use rlang::sym.

  •  Tags:  
  • Related