-
As the below shows, the output of a dataframe is a dataframe when using targets::tar_dir({
targets::tar_script({
list(
targets::tar_target(y, cars)
)
})
targets::tar_make()
targets::tar_read(y)
})
#> • start target y
#> • built target y
#> • end pipeline
#> speed dist
#> 1 4 2
#> 2 4 10
#> 3 7 4
#> 4 7 22
#> 5 8 16
#> 6 9 10
#> 7 10 18
#> 8 10 26
#> 9 10 34
#> 10 11 17
#> 11 11 28
#> 12 12 14
#> 13 12 20
#> 14 12 24
#> 15 12 28
#> 16 13 26
#> 17 13 34
#> 18 13 34
#> 19 13 46
#> 20 14 26
#> 21 14 36
#> 22 14 60
#> 23 14 80
#> 24 15 20
#> 25 15 26
#> 26 15 54
#> 27 16 32
#> 28 16 40
#> 29 17 32
#> 30 17 40
#> 31 17 50
#> 32 18 42
#> 33 18 56
#> 34 18 76
#> 35 18 84
#> 36 19 36
#> 37 19 46
#> 38 19 68
#> 39 20 32
#> 40 20 48
#> 41 20 52
#> 42 20 56
#> 43 20 64
#> 44 22 66
#> 45 23 54
#> 46 24 70
#> 47 24 92
#> 48 24 93
#> 49 24 120
#> 50 25 85
targets::tar_dir({
targets::tar_script({
list(
tarchetypes::tar_map(
list(a = list(cars)),
names = id,
targets::tar_target(y, a)
)
)
})
targets::tar_make()
targets::tar_read(y_355adbf5)
})
#> • start target y_355adbf5
#> • built target y_355adbf5
#> • end pipeline
#> [[1]]
#> [1] 4 4 7 7 8 9 10 10 10 11 11 12 12 12 12 13 13 13 13 14 14 14 14 15 15
#> [26] 15 16 16 17 17 17 18 18 18 18 19 19 19 20 20 20 20 20 22 23 24 24 24 24 25
#>
#> [[2]]
#> [1] 2 10 4 22 16 10 18 26 34 17 28 14 20 24 28 26 34 34 46
#> [20] 26 36 60 80 20 26 54 32 40 32 40 50 42 56 76 84 36 46 68
#> [39] 32 48 52 56 64 66 54 70 92 93 120 85 Created on 2021-09-28 by the reprex package (v1.0.0) Session info
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
targets::tar_script({
list(
tarchetypes::tar_map(
list(a = list(cars)),
names = id,
targets::tar_target(y, a)
)
)
})
targets::tar_manifest()$command
#> [1] "list(c(4, 4, 7, 7, 8, 9, 10, 10, 10, 11, 11, 12, 12, \\n 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 16, \\n 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 20, 20, 20, 20, 20, \\n 22, 23, 24, 24, 24, 24, 25), c(2, 10, 4, 22, 16, 10, 18, \\n 26, 34, 17, 28, 14, 20, 24, 28, 26, 34, 34, 46, 26, 36, 60, \\n 80, 20, 26, 54, 32, 40, 32, 40, 50, 42, 56, 76, 84, 36, 46, \\n 68, 32, 48, 52, 56, 64, 66, 54, 70, 92, 93, 120, 85))" Created on 2021-09-28 by the reprex package (v2.0.1) Instead, I recommend passing the symbol targets::tar_script({
list(
tarchetypes::tar_map(
list(a = list(as.symbol("cars"))),
names = id,
targets::tar_target(y, a)
)
)
})
targets::tar_manifest()$command
#> [1] "cars" Created on 2021-09-28 by the reprex package (v2.0.1) |
Beta Was this translation helpful? Give feedback.
-
Thanks! Has this always been the case? I have a project in which I did this and it worked fine. |
Beta Was this translation helpful? Give feedback.
tar_map()
works by creating the R expressions for target commands. This works well for atomic scalar values like character strings and numerics (also symbols), but not so well with complicated objects with attributes. In your case,tar_map()
is trying to turn thecars
data frame into an R expression that evaluates to that data frame.