tar_map over tibble list-column drops class

54 Views Asked by At

Consider this reprex:

targets::tar_dir({ # tar_dir() runs code from a temporary directory.
targets::tar_script({

  library(dplyr)

  values_df = tibble(index = 1:3, df = list(mtcars))

  list(
    tarchetypes::tar_map(
      values_df, names = "index",
      targets::tar_target(x, slice(df, index))
    )
  )
})
targets::tar_manifest()
})
#> # A tibble: 3 × 2
#>   name  command
#>   <chr> <chr>
#> 1 x_1   "slice(list(c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, \n     24.4, 22.8, …
#> 2 x_2   "slice(list(c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, \n     24.4, 22.8, …
#> 3 x_3   "slice(list(c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, \n     24.4, 22.8, …

As you can see, values_df is a tibble with a numeric column "index" and a list column of data frames "df". However tar_map seems to drop the data frame class of the "df" elements, which will cause an error (because dplyr::slice() does not operate on lists). Am I doing something wrong? How do I prevent tar_map() from dropping the class of the elements of the "df" list column?

0

There are 0 best solutions below