简体   繁体   中英

Rename multiple R Markdowns using map() in purrr and makeDataReport()

I want to rename a list of R Markdowns from a group split. Each dataframe has their own name in the list. My question is that I want to use makeDataReport() to generate a R Markdown report for each group split but the function gives me an error on renaming the new R Markdown output.

library(palmerpenguins)
library(dataReporter)
split(penguins, penguins$island) %>% 
  map(makeDataReport)

Data report generation is finished. Please wait while your output file is being rendered.
Error in .f(.x[[i]], ...) : 
  The file name(s) to be used by dataReporter, dataReporter_.x__i__.Rmd and dataReporter_.x__i__.pdf, is(are) already in use. We recommend trying one of the following solutions: 
 - rename your dataReporter output file using the "file" option 
 - Add a volume number to your file name using the "vol" option 
 - check that you do not want to keep the original file and if so, use makeDataReport() with argument replace = TRUE

There's a parameter in makeDataReport I can change the output R Markdown name makeDataReport(dataframe, file = "Torgersen.Rmd") . But how do I do it in a dynamic way - renaming all of them effectively?

Expectd output:

Torgersen.Rmd
Biscoe.Rmd
Dream.Rmd
pengiuns <- split(penguins, penguins$island) 
pengiuns %>% 
  map(~makeDataReport(., file = paste0(unique(.$island),".Rmd")))

#Edit to use the names instead of the column

pengiunsList <- split(penguins, penguins$island) 
pengiunsList %>% 
  map2(names(pengiunsList), ~makeDataReport(.x, file = paste0(.y,".Rmd")))

#Edit2: A third solution I didnt know about till just now

pengiunsList <- split(penguins, penguins$island) 
pengiunsList %>% 
  imap(~makeDataReport(.x, file = paste0(.y,".Rmd")))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM