In order to produce a markdown document with some strucure like
"Name and ID: %s Authors: %s Date of revision: %s"?
and looped over
I tried
reduce(as.list(letters[1:3]),sprintf,fmt="%s %s %s")
which doesn't work, it throws the error
Error in fn(out, elt, ...) : too few arguments
I expected
[1] "a b c"
since
reduce(as.list(letters[1:2]),sprintf,fmt="%s %s")
works and outputs
[1] "a b"
> sessionInfo()
> R version 4.3.2 (2023-10-31 ucrt)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
\[1\] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8
\[4\] LC_NUMERIC=C LC_TIME=English_United States.utf8
time zone: Europe/Paris
tzcode source: internal
attached base packages:
\[1\] stats graphics grDevices utils datasets methods base
other attached packages:
\[1\] purrr_1.0.2
loaded via a namespace (and not attached):
\[1\] compiler_4.3.2 magrittr_2.0.3 cli_3.6.2 tools_4.3.2 rstudioapi_0.15.0 vctrs_0.6.5 lifecycle_1.0.4 rlang_1.1.3
>
If
reduceis needed you could achieve your desired result by usingfmt="%s %s":From the docs (
?purrr::reduce) the function.fshould beHence, for your example
reducewill pass two arguments tosprintf, the first is the accumulated value from the previous step and the second argument is the next value from your list of letters. But as you specified a format string with 3 arguments you get an error.