Get an indication of which R statement can be executed on the SQL database. dcmodifydb translates R statements into SQL statement. This works for many scenario's but not all R statements can be translated into SQL. This function checks whether a modification rule can be executed on the database.
Arguments
- m
modifier()
object- tab
tbl object
- n
number of records to use in this check
- warn
generate warnings for non-working rules
- sql_warn
generate warnings with sql code for non-working rules
Examples
person <- dbplyr::memdb_frame(age = 12, salary = 3000)
library(dcmodify)
correction_rules <- modifier( if (age < 16) salary = 0
, if (retired == TRUE) salary = 0
)
# second rule is not working, because retired is not available
is_working_db(correction_rules, person, warn = FALSE)
#> [1] TRUE FALSE
# show warnings (default)
is_working_db(correction_rules, person, warn = TRUE)
#> Warning: The following rule(s) are not working on the db:
#>
#> - M2: if (retired == TRUE) salary = 0
#>
#> --------------------------------------------------------------
#> use 'is_working_db' with sql_warn=TRUE for more information
#> --------------------------------------------------------------
#> [1] TRUE FALSE
# show the sql statements that are not working
is_working_db(correction_rules, person, warn = FALSE, sql_warn = TRUE)
#> Warning: The following sql statements are not working on the database:
#>
#> -- Rule M2
#> UPDATE `dcmodifydb_7714898`
#> SET `salary` = 0.0
#> WHERE `retired` = 1;
#> [1] TRUE FALSE