-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
map as rerun replacement has weird behavior? #1118
Comments
Could you please provide a simpler example that illustrates the problem? (Maybe just be deleting all the arguments that argument actually used?) |
Ok, how about this:
It looks like the "..." in the one_run() is getting mapped to the anonymous function's initial argument, which is the counter from map? |
I think you're running into the complexities of the library(purrr)
one_run <- function(a_flag = FALSE, ...) {
if (a_flag ) {
paste0("dta-", a_flag)
} else {
"res"
}
}
run_sim <- function( reps, ... ) {
purrr::map_chr(1:reps, \(i) one_run( ... ))
}
run_sim(reps = 4, a_flag = TRUE)
#> [1] "dta-TRUE" "dta-TRUE" "dta-TRUE" "dta-TRUE"
run_sim(reps = 4, a_flag = FALSE)
#> [1] "res" "res" "res" "res" Created on 2024-07-23 with reprex v2.1.0 |
Ok, so the "~" method has some weirdness; I will try and update my coding habits to (i). I like the explicitness of the parameter, at least. :-) |
I believe the following code should print out "res" four times under the first map call below (it does) and also the second (it doesn't). Somehow the indices 1:reps in the map call are getting passed to the ~ one_run() syntax, and that is getting picked up by the 'data_only' variable, and I am not sure why (on my system)?
Session info
The text was updated successfully, but these errors were encountered: