I want to globally add a parameter to a function after import. So in future function calls the function should be always called with the set parameter. In this case, I want to add the function parameter in_schema("abc") to the function tbl from dplyr.
Normally, I would use the source code and modify the function parameters, save and source it. But in this case, I am already failing to get a proper source code file.
getAnywhere("tbl.DBIConnection")
A single object matching 'tbl.DBIConnection' was found It was found in the following places registered S3 method for tbl from namespace dplyr namespace:dplyr with value
function (src, from, ...) { check_dbplyr() tbl(dbplyr::src_dbi(src, auto_disconnect = FALSE), from = from, ...) }
How could I modify the tbl-function (in a script file) so future calls always use a certain Scheme?
like so:
tbl(connection, table, in_schema("abc"))
without having to provide the in_schema parameter all the time.
Don't copy and modify the function, it's messy, do something like this instead :
tbl_abc <- function(src, from, ...){
tbl(src, in_schema("abc", from), ...)
}
btw tbl(connection, table, in_schema("abc"))
is improper syntax, in_schema("abc")
needs a second argument, and it's passed to the ...
, which are not used by tbl.DBIConnection()