I have multiple rasters in a R targets pipeline that I load with tar_files()
and then iterate over it in the next target to add one column per file to a matrix. However, only the first column is created. Here is a reprex without using files:
library(targets)
tar_script(
{
add_column <- function(letter) {
matrix(rep(letter, 10), ncol = 1)
}
list(
tar_target(letters, letters),
tar_target(
added_columns,
add_column(letters),
pattern = map(letters)
)
)
},
ask = FALSE
)
tar_make()
How I can get a matrix with a column for each iteration?
When I load the result using tar_load(add_columns)
it only has the first column. In the case with rasters, I used terra::extract
to get one vector for each iteration, when I load the result, there are all columns but filled with NA
except the first one.