I have a list of lists (mask_pairs_list), and each "sublist" has 2 Nifti files so it looks something like this.
I'm looping through this list for (z in mask_pairs_list)
and doing something with the "heat map" and "mask" within each element/sublist of the master "mask_pairs_list". I then want to save the resulting Nifti file with a name that includes the name of the sublist like "mordor2_result" or "apple10_result". The problem is when I try to get a character vector within the for loop of the sublist name by using name_placeholder <- names(z)
it gets the names within the sublist and returns "heatmap" and "mask". How would I essentially go a layer out, and get the name of the sublist itself?
Thanks!
Something like this should work:
The key is using
sapply(..., simplify=FALSE, USE.NAMES=TRUE)
to get a named list. Oddly,lapply(...)
does not accept theUSE.NAMES=...
argument, so you have to usesapply(..., simplify=FALSE)
which is equivalent tolapply(...)
.In this example my
fun(...)
just applies the mask to the heat map. You would have a differentfun(...)
and use something other thanwrite.csv(...)
obviously.