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

Plot data is dependent on device, causing errors and spurious new devices #20

Closed
lpfgarcia opened this issue Nov 19, 2015 · 12 comments
Closed
Labels
Milestone

Comments

@lpfgarcia
Copy link

Dear,

I'm trying to run the exactly example code about rpart from the Vignette and had this error in the function dendro_data():

model <- rpart(Kyphosis ~ Age + Number + Start,  method = "class", data = kyphosis)
ddata <- dendro_data(model)

Error in rpartco(x) : 
  no information available on parameters from previous call to plot()

Do you know what is the problem?

Regards,
Luis

@lpfgarcia lpfgarcia changed the title Rpart Error dendro_data error for rpart Nov 19, 2015
@andrie
Copy link
Owner

andrie commented Nov 19, 2015

Interesting, thanks for the report.

This happens when you don't explicitly load the rpart package. Try this to make the problem go away.

library(ggdendro)
library(rpart)

model <- rpart(Kyphosis ~ Age + Number + Start, method = "class", data = kyphosis)
ddata <- dendro_data(model)

@andrie andrie added the Bug label Nov 19, 2015
@andrie
Copy link
Owner

andrie commented Nov 19, 2015

To do:

  • Update example to load the rpart package

@lpfgarcia
Copy link
Author

Hi Andrie,

The problem is intermittent:

>R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

> library(rpart)
> library(ggdendro)
> model <- rpart(Kyphosis ~ Age + Number + Start, method = "class", data = kyphosis)
> ddata <- dendro_data(model)
Error in rpartco(x) : 
  no information available on parameters from previous call to plot()
> model <- rpart(Kyphosis ~ Age + Number + Start, method = "class", data = kyphosis)
> ddata <- dendro_data(model)
$segments
    n     x         y  xend      yend
1  V1 1.875 0.8235294 1.875 1.0000000
2  V1 1.875 1.0000000 5.000 1.0000000
3  V1 5.000 1.0000000 5.000 0.8235294
6  V2 1.000 0.8058824 1.000 0.8235294
7  V2 1.000 0.8235294 2.750 0.8235294
8  V2 2.750 0.8235294 2.750 0.8058824
11 V3 2.000 0.7882353 2.000 0.8058824
12 V3 2.000 0.8058824 3.500 0.8058824
13 V3 3.500 0.8058824 3.500 0.7882353
16 V4 3.000 0.7294118 3.000 0.7882353
17 V4 3.000 0.7882353 4.000 0.7882353
18 V4 4.000 0.7882353 4.000 0.7294118

>$labels
       x         y       label
1 3.4375 1.0000000  Start>=8.5
2 1.8750 0.8235294 Start>=14.5
4 2.7500 0.8058824     Age< 55
6 3.5000 0.7882353    Age>=111

>$leaf_labels
  x         y   label
1 1 0.8058824 absent 
2 2 0.7882353 absent 
3 3 0.7294118 absent 
4 4 0.7294118 present
5 5 0.8235294 present

>$class
[1] "rpart"

>attr(,"class")
[1] "dendro"
> 

@DanielaVasco
Copy link

Hi Andrie,

I think the problem is in the function text.rpart().

This function calls the function rpartco(), just with the parameter x. As the parms entry is missing, the error message is sent.

I don't know why this error is intermittent, but when I put a default parms vector in the function text.rpart() the error message stopped when I called the function dendro_data.rpart.

So it seems to be the problem.

If you could check that in the code of the package, it would be great!

Kind regards,

DanielaV

@andrie
Copy link
Owner

andrie commented Apr 14, 2016

Thank you. This information was helpful.

I have traced the problem to the following:

  1. rpart::plot.rpart() computes the plotting data for each plot device separately
  2. It does this by saving the plot parameters in an object, referred to as parms in an environment, but the name of this object also contains the name of the dev.cur()
  3. the error happens in a fresh session, when plot() has not been called before.

This reproduces the problem:

library(rpart)
library(ggdendro)
model <- rpart(Kyphosis ~ Age + Number + Start,  method = "class", data = kyphosis)
ddata <- dendro_data(model)

plot.new()
ddata <- dendro_data(model)

Since the whole point of ggdendro is to compute the data independent of the plotting device, I have fixed this by explicitly passing parms where it is needed.

andrie added a commit that referenced this issue Apr 14, 2016
@andrie andrie added this to the v0.1.19 milestone Apr 14, 2016
@andrie andrie closed this as completed Apr 14, 2016
@DanielaVasco
Copy link

Hi Andrie,

Thank you very much for fixing that and for your package.
It has been really helpful for what I am doing.

Do you think it is possible to not open a new device when the function dendro_data() is called.
I have it in a loop and it opens several devices.

Thanks again.

Kind regards,
Daniela

@andrie
Copy link
Owner

andrie commented Apr 15, 2016

@DanielaVasco I opened a new issue #25

@DanielaVasco
Copy link

Dear Andrie,

I continue receiving the same error message when I call the function
dendro_data().

Thanks,
Daniela

On Thu, Apr 14, 2016 at 11:51 PM, Andrie de Vries [email protected]
wrote:

Thank you. This information was helpful.

I have traced the problem to the following:

  1. rpart::plot.rpart() computes the plotting data for each plot device
    separately
  2. It does this by saving the plot parameters in an object, referred
    to as parms in an environment, but the name of this object also
    contains the name of the dev.cur()
  3. the error happens in a fresh session, when plot() has not been
    called before.

This reproduces the problem:

library(rpart)
library(ggdendro)model <- rpart(Kyphosis ~ Age + Number + Start, method = "class", data = kyphosis)ddata <- dendro_data(model)

plot.new()ddata <- dendro_data(model)

Since the whole point of ggdendro is to compute the data independent of
the plotting device, I have fixed this by explicitly passing parms where
it is needed.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#20 (comment)

@andrie
Copy link
Owner

andrie commented Apr 18, 2016

Are you using the dev branch? This isn't in master yet.

@DanielaVasco
Copy link

DanielaVasco commented Apr 18, 2016

I am just calling the function directly.
How can I test it in the dev branch?

Thanks

@andrie
Copy link
Owner

andrie commented Apr 18, 2016

How do you install the package at the moment?

You have to install the development version from github using devtools, specifically the development branch (dev).

Use devtools::install_github() for this and set the ref = "dev" argument.

@DanielaVasco
Copy link

Thanks Andrie,

Now it is working :)

On Mon, Apr 18, 2016 at 5:28 PM, Andrie de Vries [email protected]
wrote:

How do you install the package at the moment?

You have to install the development version from github using devtools,
specifically the development branch (dev).

Use devtools::install_github() for this and set the ref = "dev" argument.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#20 (comment)

@andrie andrie changed the title dendro_data error for rpart Plot data is dependent on device, causing errors and spurious new devices Apr 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants