Closed njtierney closed 5 years ago
?register_feature()
maybe a section on "Register features" in the ?features()
docs cc @mitchelloharawild?
Ah nice - I did not see register_feature()
😓
Maybe it could be linked to in the documentation for features_set()
?
Also, with the new list of functions feature, this doesn't seem to quite work:
library(feasts)
#> Loading required package: fablelite
#>
#> Attaching package: 'feasts'
#> The following object is masked from 'package:grDevices':
#>
#> X11
feat_three <- list(min = min,
med = median,
max = max)
feat_three
#> $min
#> function (..., na.rm = FALSE) .Primitive("min")
#>
#> $med
#> function (x, na.rm = FALSE, ...)
#> UseMethod("median")
#> <bytecode: 0x7f9b90f5c7b0>
#> <environment: namespace:stats>
#>
#> $max
#> function (..., na.rm = FALSE) .Primitive("max")
library(tsibbledata)
aus_retail %>%
features(Turnover, feat_three)
#> # A tibble: 152 x 5
#> State Industry min med max
#> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Australian Capit… Cafes, restaurants and catering ser… 3.4 15.7 49.1
#> 2 Australian Capit… Cafes, restaurants and takeaway foo… 6.7 26 71.2
#> 3 Australian Capit… Clothing retailing 2.7 10.4 34.7
#> 4 Australian Capit… Clothing, footwear and personal acc… 4.6 18.3 61.3
#> 5 Australian Capit… Department stores 7.4 24.5 58.3
#> 6 Australian Capit… Electrical and electronic goods ret… 3.6 18.3 58.9
#> 7 Australian Capit… Food retailing 14.6 82.6 232.
#> 8 Australian Capit… Footwear and other personal accesso… 1.9 7.35 28.3
#> 9 Australian Capit… Furniture, floor coverings, housewa… 2.5 15.6 34.1
#> 10 Australian Capit… Hardware, building and garden suppl… 2.3 10.3 36
#> # … with 142 more rows
# Register your new feature using `register_feature()`:
register_feature(feat_three,
tags = c("summary", "simple"))
#> Error in as.list(table[[pkg]]): attempt to use zero-length variable name
Created on 2019-07-08 by the reprex package (v0.2.1)
Hmm, this one is difficult. Essentially a "feature" should be a function that returns a value(s). A "feature set" is a list of features which may be named.
The user interface involves using one or more features to create a feature set, from which the features are computed.
For a package (like feasts) to create a new feature, you would use:
#' Three features
#' @export
feat_three <- function(x, ...){
c(min = min(x, ...), med = median(x, ...), max = max(x, ...)
}
And then in the .onLoad()
you would register the feature with:
register_feature(feat_three,
tags = c("summary", "simple"))
I really love the idea of listing out the features with
feature_set
:Created on 2019-07-08 by the reprex package (v0.2.1)
Say I create my own features, how do I tell
fablelite
/feasts
about them?