I am currently pulling in a data set with dbplyr using the following:
connectInfo <- dbConnect(
odbc(),
Driver = "SQL Server",
Server = "myServerName",
Database = "myDatabaseName",
Trusted_Connection = "True"
)
tbl(connectInfo, "tableName") %>%
summarise(
nbDate = LEFT(nbDate, 5),
book,
rateFeeChg
) %>%
mutate(
rateFeeChg = rateFeeChg * 100
)
With the following output:
nbDate book rateFeeChg
<chr> <chr> <dbl>
1 38348 Classic 0.0000000
2 38744 Classic 2.1270990
3 39640 Classic 2.8999999
4 40423 Classic 0.0000000
# ... with more rows
What I want to do is convert these 5 digit date values into regular looking date values inside the mutate function. I know by using the janitor library I can easily convert it, but when when I try putting
mutate(
rateFeeChg = rateFeeChg * 100,
nbDate = janitor::excel_numeric_to_date(nbDate)
)
I receive the following error:
Error in janitor::excel_numeric_to_date(nbDate) :
object 'nbDate' not found
dbplyr
chain either has an adhoc translation to SQL, or is tried as an SQL function, so you can't use the code from another package there, unless you usecollect
first of course. – Moody_Mudskipperas.Date
is translated, so you may be able to use it, but I believe excel dates have a different zero than R dates so you may have to add or substract a constant. before transforming. – Moody_Mudskipperas.Date(as.numeric(nbDate)+whatever_constant_is_needed)
– Moody_Mudskipper