Skip to content

Commit

Permalink
version 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkaye97 authored and cran-robot committed Sep 20, 2021
1 parent da3749c commit c8ae40b
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 135 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: slackr
Title: Send Messages, Images, R Objects and Files to 'Slack'
Channels/Users
Version: 3.0.1
Version: 3.2.0
Author: Bob Rudis [aut, cre], Jay Jacobs [ctb], David Severski [ctb],
Quinn Weber [ctb], Konrad Karczewski [ctb], Shinya Uryu [ctb], Gregory
Jefferis [ctb], Ed Niles [ctb], Rick Saporta [ctb], Jonathan Sidi
Expand All @@ -25,13 +25,14 @@ BugReports: https://github.com/mrkaye97/slackr/issues
Depends: R (>= 3.3.0)
Imports: cachem (>= 1.0.4), dplyr, ggplot2, graphics, grDevices, httr
(>= 1.4.2), jsonlite, magrittr, memoise (>= 2.0.0), methods,
reprex (>= 2.0.1), rlang, tibble, utils, withr
Suggests: covr, knitr, rmarkdown, testthat (>= 3.0.0), texPreview
rlang, tibble, utils, withr
Suggests: covr, knitr, rmarkdown, svglite, testthat (>= 3.0.0),
texPreview
VignetteBuilder: knitr
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.1.1
NeedsCompilation: no
Packaged: 2021-08-11 23:13:24 UTC; matt
Packaged: 2021-09-20 14:54:49 UTC; matt
Repository: CRAN
Date/Publication: 2021-08-20 08:50:02 UTC
Date/Publication: 2021-09-20 15:10:02 UTC
26 changes: 14 additions & 12 deletions MD5
@@ -1,24 +1,25 @@
8a8e49aadd5b1017ff2dd41b178631a7 *DESCRIPTION
3f862cd5465b8931b7d165f37d40c8fb *DESCRIPTION
b5c243c35e6b712ecfe223711365f790 *LICENSE
5daaa176f02575f4939f43d36afb2e6b *NAMESPACE
18ebd967cf326cd28c2873ba18e85a0c *NEWS.md
d0a917af2b1072ccaa4f107fdbbdeeb1 *R/call_slack_api.R
d3cde3e3f8253fec0c771c4b9ae659a5 *NAMESPACE
c205826b56e76e29272baff9a4b6a773 *NEWS.md
303a6b14aea92f1cec82012bfb49d704 *R/call_slack_api.R
d98dc0166408a6b5b4178942ecbec893 *R/call_slack_internals.R
c0149632e4a85401ac909c434561d270 *R/gg_slackr.R
d2318846e7391d647270d4c2ac139384 *R/globals.R
0faf10c4e51332c0d4ba6eed42da7db0 *R/gg_slackr.R
3763cb9344d9528905647e6fc5c3ba92 *R/globals.R
9efcb1db246edb1eac937e2d7bc2fd6a *R/internals.R
237c5a9cd2d0ef882eebb1a47d98aa84 *R/register_onexit.R
7a3b341e6b5b4ac91c538aa396a80895 *R/slackr.R
371a30c1a50126cfbfa885a911d85ea0 *R/slackr_bot.r
a97a7b33a6be86759170c051eeb3c0a3 *R/slackr.R
528b3993c3e30256502fa77abcfaa31e *R/slackr_bot.r
50620febe5b1afe513446f27c2ad4bca *R/slackr_csv.R
c756edfb9f2864b1b7f90087785f6d1d *R/slackr_delete.R
831bb33ff735b5837b0764c928ebf8a5 *R/slackr_dev.R
6d8943d49aacf152def7de81635dd685 *R/slackr_history.R
16d0a1ca41c004d4fe75447dddf6ab55 *R/slackr_save.R
501dd5393661f4e0bfe8875da8a3a7db *R/slackr_setup.r
da030a16dbe379e28fccece157aa079c *R/slackr_tex.R
c0303983f5cb7fe4b28c870d4f89635d *R/slackr_tex.R
1cd361bab10f354f9c04d7951e92ca8e *R/slackr_upload.R
950ccdb6f6f92141ddad356540afc7dd *R/slackr_utils.R
4b3ae55640f6896cdddde268c5b0f9c1 *R/slackr_utils.R
b56ff2b193ecba52f9ec7f3b10cca008 *R/utils-pipe.R
7fb1ed813aa49d6c7980016f8cb49f02 *build/vignette.rds
9bc38243f4829f69142c1e2d89ca557f *inst/doc/scoped-bot-setup.R
5fb60af98e6b0b06ce7995ad944b0702 *inst/doc/scoped-bot-setup.Rmd
Expand All @@ -34,7 +35,8 @@ e692e26589972134a8345cf07a99209f *man/auth_test.Rd
4b46fe2772f75880f3289966495bcac8 *man/convert_response_to_tibble.Rd
ebfe2beeac5e5cec8b60261fc628b6eb *man/create_config_file.Rd
306d03a83a7503a539f3e823903f64f2 *man/figures/logo.png
d28417f8cf0068ac3674f79dea5bcf78 *man/ggslackr.Rd
764058b15c861aaac6f152cc6045b6b6 *man/ggslackr.Rd
8f4aad003a999fae004ba9361f9a99d6 *man/pipe.Rd
4217725495d65c6b8e4730cc9af0e57f *man/register_onexit.Rd
decaf6965ce1e621d6221aee9961f498 *man/slackr.Rd
c338b1b9c9622aac57c0e2eacba5f80e *man/slackr_bot.Rd
Expand All @@ -58,7 +60,7 @@ a60ccca7306def1046c65860b91ca6f5 *tests/testthat.R
0daf7d92b763992f5b78ec3c42b48e1a *tests/testthat/Rplots.pdf
18d23525e7ababf8d18d9d5675435852 *tests/testthat/test-connection.R
678c7164c7dd2092511dddd2d472821f *tests/testthat/test-helpers.R
ba3e6fde4fc7e8de94133f62fd01c5f1 *tests/testthat/test-posting.R
3dc5c77329e42a8daa8b5acf8dab60d0 *tests/testthat/test-posting.R
e132e71ab7654adde8f4f8e2269ae24e *tests/testthat/test-zconfig.R
5fb60af98e6b0b06ce7995ad944b0702 *vignettes/scoped-bot-setup.Rmd
bf707a12850358a074bc561b0aab9a26 *vignettes/using-slackr.Rmd
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(auth_test)
export(call_slack_api)
export(convert_response_to_tibble)
Expand Down Expand Up @@ -29,6 +30,7 @@ importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,distinct)
importFrom(dplyr,left_join)
importFrom(dplyr,rename)
importFrom(dplyr,setdiff)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_point)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
@@ -1,3 +1,17 @@
# slackr 3.2.0

* `slackr` and `slackr_bot` no longer rely on `reprex`, as `prex_r` would fail when an eval environment needed to be specified, but couldn't.

# slackr 3.1.1

* `slackr_ims` bug fix.
* Using `usethis::use_pipe()` to import `{magrittr}`'s pipe.

# slackr 3.1.0

* Allows `ggslackr` to post multiple file types
* Fixes a bug in `slackr` and `slackr_bot` that led to garbled output

# slackr 3.0.1

Fixes to a couple of bugs
Expand Down
2 changes: 0 additions & 2 deletions R/call_slack_api.R
Expand Up @@ -222,7 +222,6 @@ with_pagination <- function(fun, extract) {
#'
#' @references https://api.slack.com/methods/auth.test
#' @export
#' @importFrom magrittr %>%
#' @importFrom jsonlite fromJSON
#'
#' @examples
Expand All @@ -243,7 +242,6 @@ auth_test <- function(token = Sys.getenv("SLACK_TOKEN")) {
#'
#' @param x The Slack API response object, returned from [call_slack_api].
#' @param element The name of the list element to extract.
#' @importFrom magrittr %>%
#' @importFrom jsonlite fromJSON
#' @importFrom tibble as_tibble
#' @importFrom httr content
Expand Down
7 changes: 6 additions & 1 deletion R/gg_slackr.R
Expand Up @@ -18,6 +18,7 @@
#' @param initial_comment The message text introducing the file in specified channels.
#' @param thread_ts Provide another message's ts value to upload this file as a reply. Never use a reply's ts value; use its parent instead.
#' @param title Title of file.
#' @param device the file extension to use. Options: "png", "eps", "ps", "pdf", "jpeg", "tiff", "bmp", "svg". Default: "png".
#' @param ... other arguments passed to graphics device.
#' @importFrom ggplot2 ggsave last_plot ggplot aes geom_point
#' @importFrom graphics par
Expand All @@ -41,8 +42,12 @@ ggslackr <- function(plot = last_plot(),
initial_comment = NULL,
thread_ts = NULL,
title = NULL,
device = c("png", "eps", "ps", "pdf", "jpeg", "tiff", "bmp", "svg"),
...) {
ftmp <- tempfile(file, fileext = ".png")

ext <- paste0(".", match.arg(device))
ftmp <- tempfile(file, fileext = ext)

ggsave(
filename = ftmp,
plot = plot,
Expand Down
2 changes: 0 additions & 2 deletions R/globals.R
@@ -1,5 +1,3 @@
prex_r <- utils::getFromNamespace("prex_r", "reprex")

quiet_auth <- function(token) {
suppressWarnings(auth_test(token))$ok
}
117 changes: 67 additions & 50 deletions R/slackr.R
Expand Up @@ -48,60 +48,77 @@ slackr <- function(...,
# get the arglist
args <- substitute(list(...))[-1L]

modes_to_not_prex <- c("integer", "double", "complex", "raw", "logical", "character", "numeric")

## map over each thing passed to `slackr` and evaluate it
output <- lapply(
args,
function(.x) {
if (mode(.x) %in% modes_to_not_prex) {
.x
} else {
inform(
"slackr now relies on `reprex` for rendering.\nRendering messages will print, and reprex output will be saved to the clipboard.\nYou can directly paste the results into Slack.\n\n",
.frequency = "once",
.frequency_id = "36531017-f90e-4e39-8e39-4c9042634cb7"
)
eval(call2(prex_r, .x, input = tempfile(), html_preview = FALSE, render = TRUE, style = FALSE))
# setup in-memory sink
rval <- NULL
fil <- textConnection("rval", "w", local = TRUE)

sink(fil)
on.exit({
sink()
close(fil)
})

# where we'll need to eval expressions
pf <- parent.frame()

# how we'll eval expressions
evalVis <- function(expr) withVisible(eval(expr, pf))

# for each expression
for (i in seq_along(args)) {
expr <- args[[i]]

# do something, note all the newlines...Slack ``` needs them
tmp <- switch(mode(expr),
# if it's actually an expresison, iterate over it
expression = {
cat(sprintf("> %s\n", deparse(expr)))
lapply(expr, evalVis)
},
# if it's a call or a name, eval, printing run output as if in console
call = ,
name = {
cat(sprintf("> %s\n", deparse(expr)))
list(evalVis(expr))
},
# if pretty much anything else (i.e. a bare value) just output it
integer = ,
double = ,
complex = ,
raw = ,
logical = ,
numeric = cat(sprintf("%s\n\n", as.character(expr))),
character = cat(sprintf("%s\n\n", expr)),
abort("mode of argument not handled at present by slackr")
)

for (item in tmp) {

if (item$visible) {
print(item$value)
cat("\n")
}
}
) %>%
lapply(
function(.x) {
if (mode(.x) %in% modes_to_not_prex) {
.x
} else {
.x <- .x$result
.x[1] <- paste(">", .x[1])
paste(.x, collapse = "\n")
}
}
) %>%
paste(collapse = "\n\n")

if ((Sys.getenv("SLACKR_ERRORS") != "IGNORE") && grepl("Error: ", output)) {
error_message <- sprintf(
"Found a (potential) error in `slackr` call. Attempt at parsing the error:\n\n %s\n\nWe tried to extract the call for you too:\n\n %s\n\nNo message was posted.\nYou can ignore this warning and post the message with `Sys.setenv('SLACKR_ERRORS' = 'IGNORE')`.\n\n",
gsub("\n", "\n ", output),
deparse(sys.call())
)
}

on.exit()

abort(
error_message
sink()
close(fil)

# combined all of them (rval is a character vector)
output <- paste0(rval, collapse = "\n")

resp <-
post_message(
token = token,
channel = channel,
username = username,
emoji = icon_emoji,
txt = sprintf("```%s```", output),
link_names = 1
)
} else {
resp <-
post_message(
token = token,
channel = channel,
username = username,
emoji = icon_emoji,
txt = sprintf("```%s```", output),
link_names = 1,
thread_ts = thread_ts,
reply_broadcast = reply_broadcast
)
}

}

invisible(resp)
Expand Down

0 comments on commit c8ae40b

Please sign in to comment.