Option to disable multiple map behavior of mirai_map()
#147
Replies: 1 comment 4 replies
-
Thank you, this is immensely useful. What this all boils down to, I think, is a shortcoming in the current implementation of However, I would not resort to adding a The clue here is in the documentation - I had intended the 'multi-map' behaviour to apply to '2D' objects i.e. matrices / dataframes, where I think the intent would be clear to map over the rows, as In light of this, I intend to remedy the situation with limiting the 'multi-map' behaviour to matrix and data frame types. Then your example (a list) would work by default - and I think this is the correct default. The solution would retain flexibility as you could still pass in a list of arguments for multi-map by simply wrapping in I hope this remains intuitive. My preferred alternative otherwise would be to split the behaviours into two functions. |
Beta Was this translation helpful? Give feedback.
-
Originally brought up in #137 . I wanted to check if it would be possible to add an option to disable the multiple map behavior of
mirai_map()
. I can create a list of five matrices like this:I can easily use
lapply()
&colSums()
to get a list of length five with the column sums of each one:But if I try to do the same thing with
mirai_map()
it errors out because it's trying to applycolSums()
row-wise:A similar thing will happen with data frames of course. This is just a toy example, but in my usual programming style lists of matrices / data frames are fairly common and I usually want to apply a function to each matrix as a whole, not each row of each matrix.
In the issue on package guidance, when I say I adapted the source code of
mirai_map()
, I mean that I literally just pulled out lines 194-205 + 216 here and handed them my inputs and function as.x
and.f
. I want the behavior of theelse
expression there, but the multiple map conditioncond
puts me in theif
expression.The functionality I'm suggesting would be to add
.multi_map = TRUE
to the arguments ofmirai_map()
and change the condition here from(cond)
to(cond && .multi_map)
. That way I could do this:and
mirai_res
gives me the same result aslapply_res
. I tried it on a local installation and it worked as I expected it to, though I wasn't able to tell if it negatively impacted any of the tests.Anyway, this would be useful to me, but perhaps this is somehow counter to the design philosophy of
mirai
or adds some other preclusive complication that I'm unable to foresee. Just thought I'd bring it up as the default behavior it was a bit counter-intuitive to me at first.Beta Was this translation helpful? Give feedback.
All reactions