How can I get the same behavior when passing in the full function as an argument? That is, I want my_func(sample(1:10, size = 1)) to produce a 5 element vector with each element being the result of an independent call to sample(1:10, size = 1)
Here's your function: my_func <- function(FUN){map_dbl(1:5, ~ FUN)}.
What I understand is that you expect that this function will take any function, say f as an argument and return c(f(1), f(2), f(3), f(4), f(5)). So, if you use a function that doesn't really depend its argument, it'll be same as 5 repetitions of the same function.
Is that so?
If yes, then it's not doing anything as such. It doesn't check whether FUN is a function or not, and if it's not, it doesn't care. It actually takes a number as an argument, and returns that 5 times.
So, if you use a function that doesn't really depend its argument, it'll be same as 5 repetitions of the same function. Is that so?
Yes. But I want these repetitions to be "fresh", that is, not as if the same seed were set before each one. So, sample() should not produce the same answer 5 times in a row.
I would have done simply this:
But, my issue is that this code needs to run within another function. So, I could use map_dbl, as in your example, but then I get: