Use case:

  • Data from some IDS changes.
  • We want to update the datasets.

Click here on how to use the R6 class Xtractor.

library(fxtract)
xtractor = Xtractor$new("xtractor")
xtractor$add_data(iris, group_by = "Species")

fun1 = function(data) {
  c(mean_sepal_length = mean(data$Sepal.Length),
    sd_sepal_length = sd(data$Sepal.Length))
}

fun2 = function(data) {
  c(mean_petal_length = mean(data$Petal.Length),
    sd_petal_length = sd(data$Petal.Length))
}

xtractor$add_feature(fun1)
xtractor$add_feature(fun2)
xtractor$calc_features()

All features have been calculated:

xtractor$results
##      Species mean_sepal_length sd_sepal_length mean_petal_length
## 1     setosa             5.006       0.3524897             1.462
## 2 versicolor             5.936       0.5161711             4.260
## 3  virginica             6.588       0.6358796             5.552
##   sd_petal_length
## 1       0.1736640
## 2       0.4699110
## 3       0.5518947

Let’s change the dataset for the species virginica:

library(dplyr)
iris_vers = iris %>% filter(Species == "virginica")
iris_vers$Sepal.Length = abs(rnorm(nrow(iris_vers)))

Delete Old Data

Datasets are saved as RDS files (one file for each ID of the grouping variable). Single RDS files can be removed:

xtractor$remove_data("virginica")

Add New Data

xtractor$add_data(iris_vers, group_by = "Species")

Calculate Features

xtractor$calc_features()
xtractor$results
##      Species mean_sepal_length sd_sepal_length mean_petal_length
## 1     setosa         5.0060000       0.3524897             1.462
## 2 versicolor         5.9360000       0.5161711             4.260
## 3  virginica         0.8129688       0.5552283             5.552
##   sd_petal_length
## 1       0.1736640
## 2       0.4699110
## 3       0.5518947