A package that wants tidyvisor() to advise on its analyses and interpret
its results registers an advisor, usually from its .onLoad():
.onLoad <- function(libname, pkgname) {
if (requireNamespace("tidyvisor", quietly = TRUE)) {
tidyvisor::register_advisor(
package = pkgname,
questions = c("explore", "explain"),
classes = c("mypkg_fit"),
advise = function(x, ...) my_advise(x, ...),
interpret = function(x, ...) my_interpret(x, ...),
claims = function(x, args) "abundance" %in% args
)
}
}Registering again under the same package replaces the earlier advisor,
so a package's own registration takes precedence over the built-in one.
Usage
register_advisor(
package,
questions,
classes,
advise,
interpret,
claims = function(x, args) FALSE,
title = package
)Arguments
- package
Name of the package that provides the advisor.
- questions
The questions it answers (used by
advise()withquestion = "...").- classes
Classes of the results it can interpret.
- advise, interpret
Functions
function(x, ...)returning the advice or the interpretation, or names of functions exported bypackage.- claims
A function
function(x, args)returningTRUEwhen a data framex, given with arguments namedargs, is this advisor's kind of data (used byadvise()withquestion = "auto"). It must not evaluate the arguments, which may be bare column names.- title
A short description shown by
advisors().
