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

ggplot2 dependency #5

Merged
merged 59 commits into from
Aug 25, 2017
Merged

ggplot2 dependency #5

merged 59 commits into from
Aug 25, 2017

Conversation

faizan-khan-iit
Copy link
Contributor

The motive of this PR is to solve the ggplot2 dependency that animint had in previous versions.

@faizan-khan-iit
Copy link
Contributor Author

faizan-khan-iit commented Jun 14, 2017

@tdhock Ever since I added the ggplot2 code, I see this error message while trying to build the package:

Error in eval(expr, envir, enclos) : could not find function "grob"
Error : unable to load R code in package 'animint2'
ERROR: lazy loading failed for package 'animint2'

I have done the following but the error is recurring:

  1. Using collate I tried to shuffle the order of some relevant files but it didn't work. Currently I use the same collate description as from the ggplot2 package, and then load all the animint code.
  2. I added the Imports and Suggests fields exactly from the ggplot2 code. Still the error persists.

Any ideas??

Edit: Stupid mistake. Forgot to update the NAMESPACE file. Package builds now.
On that note, can we set it up to update automatically??

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017

grob is defined in the grid pacakge, maybe you need to add that to our imports?

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017

more generally you should check the NAMESPACE file from ggplot2 and copy all the stuff that they import

@faizan-khan-iit
Copy link
Contributor Author

@tdhock Could you list the downfalls to this approach?

  1. We fork ggplot2
  2. Rename the package to say ggplot2Animint
  3. Make the changes there and use it for our purposes

I think this way, both of our problems get solved:

  1. We don't have to worry about the ggplot2 version, since users can use the original CRAN version (at least I think its possible)
  2. We still have all the freedom, since we won't be sending the ggplot2 guys any PRs

I was thinking along these lines. Is it possible(to have two versions of ggplot2 with different names in an environment)? If yes, is it doable?

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017

I don't understand, can you please clarify?

@faizan-khan-iit
Copy link
Contributor Author

The problem earlier was that users could only have one version of ggplot2. So our forked version, say v2.1.0, was installed by replacing the CRAN version.

If we change the name to ggplot2Animint (say), the user will still have his CRAN version of ggplot2. So We could depend on our ggplot2Animint fork, so when the user installs animint2, ggplot2Animint gets installed too. That way, we could solve both the problems. The user can have his updated version of ggplot2 from CRAN, and we could use the code in ggplot2Animint for our purposes. If it is possible, that is.

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017

I guess it is possible, but what is the benefit of having the separate ggplot2Animint package? Why not just put everythign in animint2?

@faizan-khan-iit
Copy link
Contributor Author

faizan-khan-iit commented Jun 14, 2017

Yes, I mean it is technically the same thing, but I think it would be neater to just copy their repo along with the testing framework to make sure we don't break anything critical. Additionally we will also need to add our own tests.

Also, like you mentioned, using the new ggplot2Animint package, we could first create static plots before passing them to animint2, much like we used to before. I think it will be much more easily done this way.

Using the current approach, there will always be that task of chipping away the useless code; while I think we could just leave that as it is in the other package, without much hassle. Also, we could easily track any significant additions in the original ggplot2.

And finally just some good programming practice to separate the animation code from the static code. Tracking bugs will be easier if I know that the ggplot2 code is working as it should.

Most of this can be done the current way too. But I would prefer this one. Looks easier and neater.

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017

ok in that case do we change all of geom_ to ageom_ etc? or do we keep geom_?

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017

@cpsievert can you please share your opinion?

@faizan-khan-iit
Copy link
Contributor Author

We will make all the relevant changes in the newer package. For e.g.:

  1. We will change the geom names to geom_a*()
  2. We will not export the functions that are already exported from ggplot2 and are unchanged
  3. Will add the new syntax and tests for allowing the new syntax etc.

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017 via email

@tdhock
Copy link
Collaborator

tdhock commented Jun 14, 2017 via email

@faizan-khan-iit
Copy link
Contributor Author

for me it seems like making two packages is significantly more complicated than making one package (two times installation, two times CRAN checks, etc)

I was kind of thinking the other way around. The ggplot2 package passes the tests currently and should not have any problems installing, so making changes to allow the new syntax should be easier. Same for animint2.

we won't use the ggplot_build function anymore

Regarding the tests, we could definitely copy them. But from a maintainers perspective, it would be easier with a separate package because:

  1. While we may not use some of the code/tests from ggplot2, it will be time consuming to find it and remove it from the package. Let's leave them as they are in the separate package
  2. Since most of the relevant code will be in animint, we could separate the geom definitions, themes, and facet computations to the ggplot2Animint package that way

Anyway, it is just bookkeeping and I don't think there are any major advantages/disadvantages. Just my personal viewpoint. The only significant difference will be that if we maintain a separate package, we can use that to create static plots for visual testing first, like you mentioned before. I don't think we will be able to do that if we copy the code(?)

@faizan-khan-iit
Copy link
Contributor Author

@tdhock Should we depend on your fork of ggplot2, for consistency?

@tdhock
Copy link
Collaborator

tdhock commented Jun 19, 2017

hey Faizan it seems to be working fine now that I have removed the browser() statements

@tdhock
Copy link
Collaborator

tdhock commented Jun 19, 2017

actually I have to use devtools::load_all() to get it working

@tdhock
Copy link
Collaborator

tdhock commented Jun 19, 2017

> library(animint2)
> g <- ggplot()+geom_point(aes(Sepal.Length, Sepal.Width), data=iris, clickSelects="Species")
> g
> g <- ggplot()+geom_point(aes(Sepal.Length, Sepal.Width), data=iris, clickSelects="Species")
Error in plot_clone(p) : attempt to apply non-function
> devtools::load_all("~/R/animint2")
Loading animint2
> g <- ggplot()+geom_point(aes(Sepal.Length, Sepal.Width), data=iris, clickSelects="Species")
> g
> g <- ggplot()+geom_point(aes(Sepal.Length, Sepal.Width), data=iris, clickSelects="Species")
> g

@faizan-khan-iit
Copy link
Contributor Author

That is weird. Could you please try this? I am still getting the same error:

mtcars$cyl <- as.factor(mtcars$cyl)

p1 <- ggplot() + geom_point(aes(x=hp,
                                y=disp),
                             showSelected = c("cyl", "am"),
                             clickSelects = c("am"),
                             data = mtcars)

p2 <- ggplot() + geom_point(aes(x=hp,
                                y=disp,
                                showSelected = cyl),
                             data = mtcars)

p3 <- ggplot() + geom_point(aes(x=hp,
                                y=disp),
                             data = mtcars)

@tdhock
Copy link
Collaborator

tdhock commented Jun 19, 2017

works for me after load_all:

> library(animint2)
> mtcars$cyl <- as.factor(mtcars$cyl)
> p1 <- ggplot() + geom_point(aes(x=hp,
+                                 y=disp),
+                              showSelected = c("cyl", "am"),
+                              clickSelects = c("am"),
+                              data = mtcars)
Warning: Ignoring unknown parameters: showSelected
> p2 <- ggplot() + geom_point(aes(x=hp,
+                                 y=disp,
+                                 showSelected = cyl),
+                              data = mtcars)
Warning: Ignoring unknown aesthetics: showSelected
> p3 <- ggplot() + geom_point(aes(x=hp,
+                                 y=disp),
+                              data = mtcars)
> p1 <- ggplot() + geom_point(aes(x=hp,
+                                 y=disp),
+                              clickSelects = c("am"),
+                              data = mtcars)
> p3
> p3
Error in plot_clone(plot) : attempt to apply non-function
> devtools::load_all("~/R/animint2")
Loading animint2
> p3
> p1
> 

@faizan-khan-iit
Copy link
Contributor Author

Here is what I am doing:

  1. Load All
  2. Build and Reload
  3. Try running the code above
> library(animint2)
> mtcars$cyl <- as.factor(mtcars$cyl)
> p1 <- ggplot() + geom_point(aes(x=hp,
+                                 y=disp),
+                              showSelected = c("cyl", "am"),
+                              clickSelects = c("am"),
+                              data = mtcars)
Warning: Ignoring unknown parameters: showSelected
> p2 <- ggplot() + geom_point(aes(x=hp,
+                                 y=disp,
+                                 showSelected = cyl),
+                              data = mtcars)
Warning: Ignoring unknown aesthetics: showSelected
> p3 <- ggplot() + geom_point(aes(x=hp,
+                                 y=disp),
+                              data = mtcars)
> p1
> p2
Error in plot_clone(plot) : attempt to apply non-function

@tdhock
Copy link
Collaborator

tdhock commented Aug 23, 2017

I fixed the knitr test by changing knit_print.animint2 to knit_print.animint (the S3 method was not being called, so the default print method -- static ggplots -- was being used in the Rmd rendering process)

@faizan-khan-iit
Copy link
Contributor Author

@tdhock We are passing all the tests now except the compiler-gist test. So I guess we could start thinking about closing this PR. Is there anything else that can be done here?

@tdhock
Copy link
Collaborator

tdhock commented Aug 24, 2017

Hey Faizan this is great news, thanks for all your hard work!
I would say let's fix the gist test (finally) before merging this PR.

I just committed the secure string to the .travis.yml file, which I hope will fix the gist issue. otherwise maybe we need to generate a new gist api key and store it in a new travis secure https://docs.travis-ci.com/user/encryption-keys/

@faizan-khan-iit
Copy link
Contributor Author

@tdhock Thanks!

I have added the examples to the package and converted them to the new syntax but I haven't tested them yet. Maybe we could do that in a separate PR?

Also looks like we will have to generate a new gist api key..

@tdhock
Copy link
Collaborator

tdhock commented Aug 24, 2017

hey so I generated a new gist access token under github.com/settings, then I did travis encrypt GITHUB_PAT="ACCES_TOKEN_VALUE" which got me a new secure string that I put in .travis.yml, hopefully this solves the gist issue.

@tdhock
Copy link
Collaborator

tdhock commented Aug 24, 2017

ok, all tests are now passing, and I have updated the version in NEWS/DESCRIPTION/README. I give my official +1 for this PR, go ahead and merge when you are ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants