This doc should help guide you should you wish to contribute to twidlr
Contributing to twidlr will mostly involve adding a new model function. The aim is to provide users with two functions:
model(data, formula, ...)
which fits a model based on a data.frame, formula, and additional arguments.predict(fit, data, ...)
which produces predicted values (typically a vector) given a fitted model and a data.frameTo achieve this in a consistent manner, follow these steps:
To add the model function mod()
from the package pkg
:
pkg
to "Suggests" in the DESCRIPTION filedevtools::use_package("pkg", "Suggests")
. For example, devtools::use_package("randomForest", "Suggests")
lm()
from the stats package resides in "R/twidlr-stats.R"mod
, mod.default
, predict.class_of_fitted_mod
. See any "R/twidlr_*.R" file for examples.mod*
functions are defined as function(data, formula, ...)
~.
by default.mod
checks for necessary package via check_pkg("pkg")
and calls the appropriate S3 method.mod.default
does necessary data processing and returns an appropriate call to pkg::mod()
data
to a data.frame (thus allowing other square structures) and formula
to a formula (thus allowing string-based formulas) by way of coerce_args
.lm
and glm
), or data munging to be done first (e.g., xgboost and glmnet). When data munging is required (or formula
cannot be passed), be sure to add formula
as an attribute to the fitted object (again, see xgboost and glmnet for examples). This is important so that the same data munging can be done by predict
.predict.class_of_fitted_mod
is defined as function(object, data, ...)
, and returns an appropriate call to pkg::predict.class_of_mod
(or valid alternative).data <- predict_checks(data = data, ...)
, which runs generic checks and coerces data
to a data.frame.devtools::use_test("pkg")
. For example, devtools::use_test("stats")
.test_that("mod", {...})
twidlr_fit
) and a model fitted by the original package (named origina_fit
). See any of the test files for examples. See Hadley Wickham's R Packages for advice about creating tests.predict(twidlr_fit)
throw an error because data
is missing?predict()
on each fitted object return the same results?Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.