Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in ggplot2::theme(...) : could not find function "element_blank" #82

Closed
andyyao95 opened this issue Aug 12, 2015 · 11 comments
Closed

Comments

@andyyao95
Copy link

I am developing a package which has one function that calls shinystan to visualize/diagnose my MCMC sampling. The specific function call would be:

library(my_package)
## assuming this.df is in the correct dimensions
shinystan::launch_shinystan(shinystan::as.shinystan(this.df)

And then I get this error:

Loading...
Note: for large models ShinyStan may take a few moments to launch.
Loading required package: shiny

Listening on http://127.0.0.1:6658
Error in ggplot2::theme(...) : could not find function "element_blank"
Error in ggplot2::theme(...) : could not find function "element_blank"

It seems like ggplot2 was not loaded, because library(shinystan) or library(ggplot2) fixes this problem. I understand that I only imported 2 functions fromshinystan, and ggplot2 would still need to be libraried somewhere in my code. Is there anyway around this without having to depend on shinystan or ggplot2?

@dpastoor
Copy link
Collaborator

should be a reasonably straightforward fix - give me about 30 minutes and I should have a pull request in with the necessary fixes (adding explicit calls to ggplot for all the theme elements)

@jgabry
Copy link
Member

jgabry commented Aug 12, 2015

Hi Andy,

Do you have the code for your package on github or somewhere I can take a
look? Maybe we can find a way around this issue.

That said, while it's always nice to depend on as few packages as possible,
would depending on ggplot2 cause any issues for your package?

Jonah

P.S. It's cool you're using shinystan as part of your package!

On Wednesday, August 12, 2015, Andy Yao notifications@github.com wrote:

I am developing a package which has one function that calls shinystan to
visualize/diagnose my MCMC sampling. The specific function call would be:

library(my_package)

assuming this.df is in the correct dimensions

shinystan::launch_shinystan(shinystan::as.shinystan(this.df)

And then I get this error:

Loading...
Note: for large models ShinyStan may take a few moments to launch.
Loading required package: shiny

Listening on http://127.0.0.1:6658
Error in ggplot2::theme(...) : could not find function "element_blank"
Error in ggplot2::theme(...) : could not find function "element_blank"

It seems like ggplot2 was not loaded, because library(shinystan) or
library(ggplot2) fixes this problem. I understand that I only imported 2
functions from shinystan, and ggplot2 would still need to be libraried
somewhere in my code. Is there anyway around this without having to depend
on shinystan or ggplot2?


Reply to this email directly or view it on GitHub
#82.

@dpastoor
Copy link
Collaborator

hmm @jgabry so it looks like the (bigger) issue is that with the Depends on ggplot, (most) all the internal code written for shinystan doesn't explicitly call ggplot in front of every element, eg ggplot2::element_blank(). Makes it easier to type, however if any package wants to call a single function without actually loading shinystan I don't believe it will force ggplot/shiny to load

@jgabry
Copy link
Member

jgabry commented Aug 12, 2015

Yeah I had it this way because in one of the older iterations there was a
problem that required explicitly depending on ggplot2. But that problem was
sorted out a while ago so it could probably just be in imports instead of
depends now, and the functions could all be called with the ggplot2::,
which would be unfortunate for the source code but would solve this type of
problem.

On Wednesday, August 12, 2015, Devin Pastoor notifications@github.com
wrote:

hmm @jgabry https://github.com/jgabry so it looks like the (bigger)
issue is that with the Depends on ggplot, (most) all the internal code
written for shinystan doesn't explicitly call ggplot in front of every
element, eg ggplot2::element_blank(). Makes it easier to type, however if
any package wants to call a single function without actually loading
shinystan I don't believe it will force ggplot/shiny to load


Reply to this email directly or view it on GitHub
#82 (comment).

@andyyao95
Copy link
Author

Hi Jonah and Devin!

Thank you so much for such a prompt reply! My package is on github and you could access it by:

install_github("andyyao95/walkr")
library(walkr)
A <- matrix(1, ncol = 3)
b <- 1
answer <- walkr(A = A, b = b, points = 1000, chains = 5, ret.format = "list")

## this line calls shinystan
explore_walkr(answer)

All of the code is on my github! Again, I really appreciate your help!!

Edit: depending on ggplot2 is surely not a problem for me, since it is so widely used. I was just thinking/wondering that I probably shouldn't need to do that since I don't directly use ggplot2.

@dpastoor
Copy link
Collaborator

andy,

a quick and dirty fix would be to do

if(!any(grepl("package:ggplot2", search()))) {
    message("loading ggplot2 for shinystan visualizations")
    library(ggplot2, quiet =TRUE)
}

which will load ggplot if it hasn't already been loaded. Ultimately I think you'll be better off
just loading all of shinystan rather than just importing those functions, else I think you might end up picking up a lot of bugs from either ggplot or shiny functions not being available.

@andyyao95
Copy link
Author

Hi Devin,

Wonderful! I'll use that quick and dirty fix for now. I'll be following shinystan updates closely. If you guys update the structure of the depends/imports field I'll try it out and let you guys know. Either way, I could just use this fix or depend on ggplot2. Thanks again.

Andy

@dpastoor
Copy link
Collaborator

@andyyao95 sounds good - you might need to do that same hack for shiny and/or shinystan as well (you'll find out if it keeps crashing). So if you get any more bugs/crashes just post them here and we can track down the dependency code to make it explicit as we go.

@dpastoor dpastoor mentioned this issue Aug 12, 2015
6 tasks
@jgabry
Copy link
Member

jgabry commented Aug 13, 2015

@andyyao95 If you install shinystan from this branch does your function work without having to do library(ggplot2)?

@andyyao95
Copy link
Author

@jgabry

Hi Jonah,

This version works perfectly fine. Thank you for solving this issue!!

Andy

@jgabry
Copy link
Member

jgabry commented Aug 13, 2015

@andyyao95 great! For now these changes are just on the separate branch but
unless we find a better way or any problems with this we'll get it into the
next release too when that's ready.

On Thursday, August 13, 2015, Andy Yao notifications@github.com wrote:

@jgabry https://github.com/jgabry

Hi Jonah,

This version works perfectly fine. Thank you for solving this issue!!

Andy


Reply to this email directly or view it on GitHub
#82 (comment).

jgabry added a commit that referenced this issue Aug 19, 2015
Moves ggplot2 to Imports from Depends. Resolves #85, resolves #83, and resolves #82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants