0

I am using future_map to create several plots where I iterate through a list of variables and output/save a png file per variable to a folder. So there is no output that needs to be shown in the console or the "plot" pane.

The plotting part of the function:

  ggplot(aes(sample = value,
               color = key)) +
    stat_qq(alpha = 0.8, size = 0.5) +
    theme_light() +
    theme(legend.position = "none")  +
    stat_qq_line() +
    facet_wrap(~key,
               ncol = 4) +
    ggtitle(.var) +
    ggsave(filename = here::here(paste0(.path,
                                        .var,
                                        ".png")),
           units = "cm",
           width = 25,
           height = 10)}

How I map the function:

plan(multiprocess(workers = 10))
future_map(names_list,
           ~check_dists(df_lips_imputed, .x, "doc/distributions/testing2/"),
           verbose = FALSE)

However, after all files are created, I can see they are in the folder, this is slowly printed (takes a while, ~1k iterations):

[[1]]

[[2]]

[[3]]

...

Does anyone know how to suppress this output?

Many thanks!

Fabian
  • 1
  • 1
  • A few thoughts. One: I think this is behavior in `purrr:map` and has nothing to do with the futures/parallelization stuff. Two: `map` returns a list the same length as the list you map over. Three: not sure if this is a smart or cannonical to go about this, but maybe nesting your future_map inside another function you can return the output silently. – Michael Roswell Mar 13 '20 at 13:50
  • possibly useful: https://stackoverflow.com/a/30810537/8400969 – Michael Roswell Mar 13 '20 at 13:51
  • check out `walk` https://stackoverflow.com/a/47123420/8400969 – Michael Roswell Mar 13 '20 at 13:54
  • Thanks Michael! I tried nesting it in a function and invisible() around the function itself and both did not work. Walk works and suppresses the output, but is not parallelized. I could not find something like "future_walk". I found assigning this list (name <- future_map...) also surpresses the output, but that seems a bit dirty=) – Fabian Mar 13 '20 at 14:37

2 Answers2

1

If you install the development version of furrr with

devtools::install_github("DavisVaughan/furrr")

You can then use future_walk, which is acts like walk does versus map. With walk the function acts by side effects and so the return value is simply the input.

pgcudahy
  • 1,542
  • 13
  • 36
0

I was having the same issue. I'm not sure if this will change the time that it takes to print out the list elements at the end, but if you save your future_map call as a throwaway variable, it will save the output in that variable instead of printing out and clogging up your console or log file:

x <- future_map(names_list,
                ~check_dists(df_lips_imputed, .x, "doc/distributions/testing2/"),
                verbose = FALSE)
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
lsev
  • 1