mrkaye97 / slackr

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

slackr() cannot access variables defined within a function #168

Closed anthonypileggi closed 3 years ago

anthonypileggi commented 3 years ago

When wrapped within a function, slackr() cannot evaluate expressions involving variables that have been defined within the scope of the function.

library(slackr)
slackr_setup() 

# this works fine
x <- head(mtcars, 5)
slackr(x)

image

# when wrapped in a function, it cannot see 'y' as defined
send_cars_to_slack <- function() {
  y <- head(mtcars, 5)
  slackr(y)
}
send_cars_to_slack()

image

I wonder if this is a side-effect of using prex_r() and what environment it is evaluating in. I've also encountered the same issue when using slackr_bot().

mrkaye97 commented 3 years ago

hey @anthonypileggi, thanks for the bug report! You're almost certainly right that this is a side effect of using prex_r. What version of slackr are you on?

I'll try to repro and ship and new version. I might just roll back the mechanism slackr uses to get off of using reprex, since I think the error handling was a little better before, too.

anthonypileggi commented 3 years ago

Awesome, thanks for the quick response @mrkaye97 and all your hard work on this package!

I encountered this problem on both the cran (v3.0.1) and dev (v3.1.1) versions, but it works fine on v2.4.1.

mrkaye97 commented 3 years ago

Yep, makes sense! Thanks. 3.0.0+ relies on reprex for rendering, so that checks out. I'll write a test for this tonight and see if I can ship a fix. No guarantees till the weekend though -- I'll report back

mrkaye97 commented 3 years ago

Alright @anthonypileggi, so I've looked into this and AFAICT, there's no way around the eval environment issue that you pointed out. I'm going to roll back to the old eval scheme and then see if I can update this to something better later on.