daattali / ggExtra

📊 Add marginal histograms to ggplot2, and more ggplot2 enhancements

Home Page:http://daattali.com/shiny/ggExtra-ggMarginal-demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does ggMarginalGadget(plot) work from the Console Panel (Rstudio)?

sfd99 opened this issue · comments

commented

Hi Dean,

ggExtra = great, useful pkg!.

ggMarginalGadget(plot) or the equivalent Addin.
works great
from Rstudio's [Source Panel].

But,...
from Rstudio's [Console Panel]

Using the ggextra Vignette example,
for: ggMarginalGadget(plot)

if (interactive()) {
plot <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point()
plot2 <- ggMarginalGadget(plot)
}

pops up the interface,
but w/ this error message:
(in red letters):

Error with the advanced options:
no applicable method for 'ggplot_build'
applied to an object of class "NULL"

Does the ggMarginalGadget() Fx
work in the Rstudio [Console Panel]
or only from the [Source Panel] ?.

help!
sfd99
San Francisco
latest Rstudio, R, Ubuntu Linux 20.04.

Thanks for the report!

I've been able to pinpoint the issue to a difference between retrieving an object that has the same name as an internal function (such as plot) from within a package's function vs outside of a package function. It looks like at some point, perhaps because of changes to R, it changed.

To show you what I mean:

  • Define a variable sum <- "test"
  • Create a super basic R package
  • Create a function test <- function() { browser() } inside a file in the R folder (where package functions go)
  • Define an identical function test <- function() { browser() } but define it in the console, don't save it as a file in the package
  • Run devtools::load_all()
  • Run test() and when you have control of the console, type sum to see its value. You will get the function.
  • Now quit the debugger and try running test2() and again type sum. This time you'll get the value from the globalenv

This is why the example code using the variable name "plot" is breaking. I don't know when this started happening. I'll change the example to a different variable name.

fixed in e23ccb9

commented

Thanks Dean for the fix.
That was quick!. :-)

ggMarginal(p)
now works fine from the Rstudio [Console Panel].

But, the Addin alternative, with:
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()

ie:
highlight p in the [Console Panel]
then click on:
"ggplot Marginal Plots" in Addins,
still gives an error message:

> ggExtra:::ggMarginalGadgetAddin ()
Error in ggExtra:::ggMarginalGadgetAddin() :
Please highlight a ggplot2 plot before selecting this addin.

Yet,
the letter p in the [Console Panel]
(a ggplot),
has been hilited before clicking on the Addin.
as prescribed.

Maybe I'm missing something basic?...
sfd99
San Francisco
latest Rstudio, R, Ubuntu Linux 20.04.

ggextra Version 0.9.0.1 - installed f/GIThub.

It may have seemed quick to you but it was a very long frustrating hour of debugging for me :)

p causes the same issue. p is a function in shiny (well, actually, in htmltools), for creating paragraph in HTML. Basically you can't use a variable that is already a function.

I'll reopen this because this problem should be handled better rather than my bandaid solution of "don't do this". It's strange that this never used to be an issue

commented

Thanks, Dean!.

Your hard work
and useful R PKG contributions
are highly appreciated.

You are a true PRO...