With that naming scheme of a sf frame dat
and assuming that the geometry column is last, I'd start with
idx <- 1:length(dat)
idx <- idx[-length[dat])
idx <- idx[-c(34:37)] # example of four columns to skip
then write and test
x <- 1
f <- function (x) rasterize(dat, raster_grid, dat[[x]])
f(1)
rm(x)
Preallocate a receiver object to be identified to stack()
. Here I will assume the transformed variables can be conveniently extracted from a list
object since without a reprex
. See the FAQ I'm to lazy to reverse engineer the problem.
recv <- vector(length = length(idx)
(The default type created this way is a list. Go figure.)
Then, untested by me, this should create your list with a for
loop
for(i in seq_along(idx)) recv[i] = f(i)
or maybe
o <- lapply(dat[idx],f)
The purrr
flavors I've always found unintuitive, despite their intention to be easier to grasp, and as I got over my discomfort with punctuation/positional syntax in {base}
, I've come to prefer it as less syntax-intensive than the tidyverse
way.