How do I inherit these params from odbc::dbConnect() We have an internal function for connecting to our database and we want to list out the parameters that are available.
In the help menu I see this
However, when I use:
@inheritParams odbc::dbConnect in only brings back drv and ... definition
@inheritDotParams odbc::dbConnect it only brings back drv
When trying to understand what R is seeing, this lists the parameters of the help menu
formals(odbc:::OdbcConnection)
but roxygen2 won't use it (error: failed to find topic), and this only shows the parameters I described above
PS. I would rather inherit from the method, i.e., @inheritParams odbc::'dbConnect,OdbcDriver-method', it is safer in case the aliases change.
How did I find the answer? I work with S4 methods all the time
I see. I think the issue is we aren't making our own method. We just have a function that allows the user to pass their own connection object or default to a prod connection. This is just a skeleton, there are more steps inside of run_sql()
run_sql <- function(sql, con = NULL, ...) {
if (missing(con)) {
con <- db_prod() # custom function
}
dbGetQuery(con, sql, ...) # the '...' we want to document
if (missing(con)) {
dbDisconnect(con)
}
}
It should also work with a plain function as long as the function signature shares arguments in the referenced documentation. In this case, it only seems to share the dots ....
The ... you want to document don't seem to go to the place you think they are going to. If you expect con to be an OdbcConnection then the dots go to this method:
> getMethod(dbGetQuery, c("OdbcConnection","character"))
Method Definition:
function (conn, statement, ...)
{
.local <- function (conn, statement, n = -1, params = NULL,
immediate = is.null(params), ...)
{
rs <- dbSendQuery(conn, statement, params = params, immediate = immediate,
...)
on.exit(dbClearResult(rs))
df <- dbFetch(rs, n = n, ...)
if (!dbHasCompleted(rs)) {
warning("Pending rows", call. = FALSE)
}
df
}
.local(conn, statement, ...)
}
which actually go to the dbSendQuery,OdbcConnection,character-method and to dbFetch.
AFAIU, you expect con to be created with dbConnect with an odbc() driver. This would happen outside of your function and therefore you don't need to inheritParams for a function that is external to yours.