R6 Class Xtractor - Error Handling"

Use case:

Setup script:

unlink("fxtract_files", recursive = TRUE)
library(fxtract)
xtractor = Xtractor$new("xtractor")
xtractor$add_data(iris, group_by = "Species")

Let's write functions, which fail on different datasets:

fun1 = function(data) {
  if ("versicolor" %in% data$Species) stop("fun1 not compatible on versicolor")
  c(mean_sepal_length = mean(data$Sepal.Length),
    sd_sepal_length = sd(data$Sepal.Length))
}

fun2 = function(data) {
  if ("virginica" %in% data$Species) stop("fun2 not compatible on virginica")
  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()

We can still get the resulting dataframe with missing values for failed calculations:

xtractor$results

Get Error Messages

xtractor$error_messages

Debugging

You can get the feature function and the dataset of the ID like this:

fun = xtractor$get_feature("fun1")
df = xtractor$get_data("versicolor")

Now you can debug the function on the dataset on which the function failed.

Fix Features

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

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

xtractor$remove_feature(fun1)
xtractor$remove_feature(fun2)
xtractor$add_feature(fun1_fixed)
xtractor$add_feature(fun2_fixed)

Calculate Again

xtractor$calc_features()
xtractor$results
unlink("fxtract_files", recursive = TRUE)


Try the fxtract package in your browser

Any scripts or data that you put into this service are public.

fxtract documentation built on July 8, 2020, 5:43 p.m.