Last active
January 26, 2021 00:51
-
-
Save DavidPatShuiFong/4073a4fd50a7b10c97c1516f1a4d3e0e to your computer and use it in GitHub Desktop.
Testing behaviour of character to numeric conversion in dbplyr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df <- data.frame(x = c("1.3", "2x")) | |
| # dbplyr::test_register_src( | |
| # "mssql", | |
| # odbc::dbConnect( | |
| # odbc::odbc(), Driver = "ODBC Driver 17 for SQL Server", | |
| # Server = "<server>", UID = "<uid>", PWD = "<password>") | |
| # ) | |
| con <- src_test("mssql") | |
| db <- copy_to(con, df, "##test") | |
| out <- db %>% mutate( | |
| integer = as.integer(x), | |
| integer64 = as.integer64(x), | |
| numeric = as.numeric(x), | |
| ) %>% | |
| collect() | |
| # testthat tests | |
| expect_identical(out$integer, c(1L, NA)) | |
| expect_identical(out$integer64, bit64::as.integer64(c(1L, NA))) | |
| expect_identical(out$numeric, c(1.3, NA)) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
modified version of Gist as originally written by Hadley Wickham. For testing purposes of dbplyr in the tidyverse (tidyverse/dbplyr#555)