mrkaye97 / slackr

An R package for sending messages from R to Slack
https://matthewrkaye.com/slackr/
Other
307 stars 83 forks source link

slackr_tex dies with no_file_data #167

Closed shabbychef closed 3 years ago

shabbychef commented 3 years ago

Sending tex via slackr_tex fails with response no_file_data.

library(slackr)
library(texPreview)
# magic incantation of slackr_setup
slackr_tex("$\\sum_{n=0}^{\\infty} \\frac{1}{n!}$",title='latex',ext='png',initial_comment='foo',channel='@myname')

FWIW, I am using texPreview 1.5 on a Mac. It seems that when tex_preview is called, two files are written to the fileDir of td. Calling files_upload with file=td seems wrong to me. Indeed, I rewrote slackr_tex as:

my_tex <- function (obj, channels = Sys.getenv("SLACK_CHANNEL"), token = Sys.getenv("SLACK_TOKEN"), 
                    ext = "png", path = NULL, title = NULL, initial_comment = NULL, 
                    thread_ts = NULL, ...) {
  slackr:::check_tex_pkg()
  if (!is.null(path)) {
    td <- path
  } else {
    td <- file.path(tempdir(), "slack")
  }
  if (!dir.exists(td)) { dir.create(td) }
  texPreview::tex_preview(obj = obj, stem = "slack", fileDir = td, 
                          imgFormat = ifelse(ext == "tex", "png", ext), ...)
  fname <- file.path(td,paste0('slack.',ifelse(ext == "tex", "png", ext)))
  res <- slackr:::files_upload(file = fname, channels = channels, token = token, 
                               title = title, initial_comment = initial_comment, thread_ts = thread_ts)
  file.remove(list.files(td, pattern = "Doc", full.names = TRUE))
  if (is.null(path)) { unlink(td, recursive = TRUE) }
  invisible(res)
}

and this function works just fine in my setup.

mrkaye97 commented 3 years ago

Thanks for the bug report @shabbychef! Any interest in PRing this change? If you do, I'll be able to test it more easily on my end and can merge it into slackr 3.2.0.

shabbychef commented 3 years ago

I will, but first I am not sure why the existing code no longer works: has there been a change to tex_preview? Or does this somehow run differently on a Mac? etc. If the answer is that this function has not been tested in a while, and the API changed, I will make a PR. Otherwise I am afraid of breaking existing code...

mrkaye97 commented 3 years ago

@shabbychef Yeah, I'm not sure without looking into it. I didn't write slackr_tex, so I'll need to play around with if a bit to try to repro the issue and figure out what's going on.

And no worries about breaking the code :) that's my responsibility to worry about, not yours