knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of hybrid is to ...
You can install the development version from GitHub with:
# install.packages("devtools") devtools::install_github("romainfrancois/hybrid")
eval_hybrid()
(temporary name) evaluates an expression with eval_tidy()
with a data mask
made of hybrid leaves. An hybrid leaf is essentially the ptype
of a column marked with the
"hybrid"
class.
Giving leaves the hybrid class makes it possible to dispatch based on that class, so mean.hybrid
and +.hybrid
(currently for this POC) when passed hybrid trees (leaves included) make hybrid trees.
library(hybrid) eval_hybrid(iris, mean(Sepal.Length))
For functions that don't define hybrid methods, the computation is however as quick as possible yet still maintaining some type stability because the ptype is used in place of the real column.
eval_hybrid(iris, median(Sepal.Length))
The idea is that standard R evaluation and dispatch takes place and if we end up with an hybrid object, then perhaps the c++ code can handle it, otherwise fall back.
# these return an hybrid object because +() and mean() can handle hybrid eval_hybrid(iris, mean(Sepal.Length)) eval_hybrid(iris, Sepal.Length + Sepal.Width) eval_hybrid(iris, Sepal.Length + Sepal.Width + Petal.Length) eval_hybrid(iris, mean(Sepal.Length + Sepal.Width)) # not sensible to the call ast, as is evaluation based plus <- function(x, y) { x + y } eval_hybrid(iris, identity(mean(Sepal.Length))) eval_hybrid(iris, plus(Sepal.Length, Sepal.Width)) # No max() hybrid function so we get something not hybrid eval_hybrid(iris, mad(Sepal.Length)) # + does not handle the pattern `hybrid + not-hybrid` eval_hybrid(iris, mean(Sepal.Length) + 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.