将 initial_time_split 与 drake 一起使用时出错

Error when using initial_time_split with drake

学习如何将 drake 与 tidymodels 一起使用。

当我 运行 make(plan) 时,关于使用 rsample 的 initial_time_split() 而不仅仅是 initial_split() 的一些事情给我一个错误。我得到以下信息:

#> > target data
#> > target split_data
#> Error in UseMethod("complement"): no applicable method for 'complement' applied to an object of class "rsplit"

为了这个我真的绞尽脑汁。该功能独立运行良好(即以下工作):

我觉得我缺少一些非常基本的东西。

这是单个文件中的完整 drake 进程(这样更容易 post 堆栈溢出)。

提前感谢您的提示,关于我做错了什么。

library(drake)
library(tidyverse)
library(tidymodels)

###################################################################

generate_data <- function() {
  tibble(x = rnorm(1e5), y = rnorm(1e5))
}


split_the_data <- function(data) {
  
  data %>% 
    initial_time_split()
  
}


fit_model <- function(data) {
  
  summary(lm(y ~ x, data = data))
}



###################################################################


plan <- drake_plan(
  
  data = generate_data(),
  
  split_data = split_the_data(data),
  
  model = fit_model(training(split_data))
  
)


###################################################################


make(plan)

这应该在当前的开发版本中得到修复(从 93d60ef41119defc0432cc95d2dd6787e4a00b14 开始)。您可以使用

安装它
install.packages("remotes")
remotes::install_github("ropensci/drake")

错误发生是因为 drake 在每个目标上调用 NROW()(为了 dynamic branching 目的)并且显然 rsplit 对象上的 NROW() 错误。

library(tidyverse)
library(tidymodels)
#> ── Attaching packages ─────────────────────────────────────── tidymodels 0.1.1 ──
#> ✓ broom     0.7.0      ✓ recipes   0.1.13
#> ✓ dials     0.0.8      ✓ rsample   0.0.7 
#> ✓ infer     0.5.3      ✓ tune      0.1.1 
#> ✓ modeldata 0.0.2      ✓ workflows 0.1.2 
#> ✓ parsnip   0.1.2      ✓ yardstick 0.0.7
#> ── Conflicts ────────────────────────────────────────── tidymodels_conflicts() ──
#> x scales::discard() masks purrr::discard()
#> x dplyr::filter()   masks stats::filter()
#> x recipes::fixed()  masks stringr::fixed()
#> x dplyr::lag()      masks stats::lag()
#> x yardstick::spec() masks readr::spec()
#> x recipes::step()   masks stats::step()

generate_data <- function() {
    tibble(x = rnorm(1e5), y = rnorm(1e5))
}

split_the_data <- function(data) {
    data %>% 
        initial_time_split()
}

NROW(split_the_data(generate_data()))
#> Error in UseMethod("complement"): no applicable method for 'complement' applied to an object of class "rsplit"

reprex package (v0.3.0)

于 2020-07-23 创建

问题已在 https://github.com/ropensci/drake/issues/1300 中跟踪。