`stop_rate_excess()`

Hi ,
I am trying to send emails from R studio using the emayilii package,
The idea is to send a different report (R markdown) to different people,
I am trying to iterate through the email addresses and the parameters of R markdown using the function pwalk .. nevertheless I am getting an error related to the purrr package which I am not able to interpret .. could you please help me? it's important to highlight that the reports I am trying to send are quite heavy
Thanks for your help

Backtrace:
 1. purrr::pwalk(...)
 5. emayili (local) smtp(.)
 6. purrr (local) send_mail(...)
      at emayili/R/server.R:157:4
 7. purrr::rate_sleep(rate, quiet = quiet)
 8. purrr:::stop_rate_excess(rate)
Run `rlang::last_trace()` to see the full context.

The error message suggests that there's a problem with the rate limit when sending emails using the emayili package. It appears that the package is trying to send too many emails too quickly, and the rate limit is preventing the emails from being sent.

One way to fix this issue is to add a delay between sending emails, so that the rate limit is not exceeded. The purrr package provides the rate_sleep() function for this purpose. You can use this function to add a delay between each email that is sent. For example, you could add the following line of code before the call to emayili::smtp():

purrr::rate_sleep(1, quiet = TRUE)

This will add a delay of 1 second between each email that is sent, which should be enough to avoid exceeding the rate limit.

Another option would be to check the rate limit from your email provider and adjust the rate of sending emails accordingly.

It's worth noting that large reports will take longer to send and may cause a backlog in the email queue. It may be a good idea to send the report in multiple chunks or compress the file to reduce the size before sending.

Hi @joanmils thanks for your answer .. I tried to add this line but I am getting the following error
Error in rate_sleep(., 1, quiet = TRUE) : unused argument (1)

This is my code

pwalk(
  reports,
  function(email,x){
    log_info("{x} -> {email}")
    envelope(
      to=email,
      from=fromJSON("credentials.json")$email
    ) %>%
      subject("Try email {{ x }}")%>%
      emayili::render(RMD,params=list(year=year)) %>%
      rate_sleep(1, quiet = TRUE)%>%
      smtp()
    
  }
)

rate_sleep is not appropriate to pipe; it should be its own command line; its functionality is to introduce a delay of some length; it also doesnt take time directly it takes a rate object.
so probably something like


myrate <- rate_delay(1)
pwalk(
  reports,
  function(email,x){
    
    rate_sleep(myrate, quiet = TRUE)
    
    log_info("{x} -> {email}")
    envelope(
      to=email,
      from=fromJSON("credentials.json")$email
    ) %>%
      subject("Try email {{ x }}")%>%
      emayili::render(RMD,params=list(year=year)) %>%
      smtp()
  }
)