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

tree::tree object cannot be accessed in editor, only in console #2295

Closed
stgries opened this issue Jan 29, 2022 · 3 comments
Closed

tree::tree object cannot be accessed in editor, only in console #2295

stgries opened this issue Jan 29, 2022 · 3 comments
Labels
RStudio IDE

Comments

@stgries
Copy link

@stgries stgries commented Jan 29, 2022

When I work with the tree package, I cannot access a part of its output from an Rmd document, but I can access it with the exact same code in the console. Please find an Rmd exemplifying the problem below and the HTML report with the session info attached.

---
title: "tree::tree object cannot be accessed in editor, only in console"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Setting up an example

Let's create some small data for a `tree::tree` approach:

```{r}
rm(list=ls(all=TRUE))
library(tree); set.seed(1)
summary(x <- data.frame(
   Y=factor(rep(letters[1:2], each=250)),
   X1=c(runif(250, 1, 5), runif(250, 3, 7)),
   X2=c(runif(250, 5, 9), runif(250, 1, 5))))
```

Running a tree on this is unproblematic:

```{r}
summary(cart.1 <- tree(Y ~ X1+X2, data=x))
```

tree_bug.pdf

Now the problem

If

  • I knit the document into an HTML file (like attached), the output is shown;
  • I use each of these lines in the console, I will see the output there; BUT
  • I run the following chunk from the editor with CTRL-SHIFT-ENTER or the play button, no output is provided;
cart.1$frame
cart.1[["frame"]]
cart.1[[1]]

One time, I saw the following error message in the editor pane:

Registered S3 method overwritten by 'cli':
method     from
print.tree tree

But I wasn't able to reliably reporduce that one.

However, each of those lines will produce output when I copy and paste it into the console -- why??

xfun::session_info()
@cderv
Copy link
Collaborator

@cderv cderv commented Jan 31, 2022

Hi,

thank you for the report. I can reproduce your step.

As everything is working fine when knitting and rendering to HTML, this makes me thing it is a RStudio IDE issue. The feature to execute chunk by chunk if from the IDE support of Rmd document, specifically showing "Chunk Output Inline".
If you select, "Chunk Output in Console" , in the menu you'll see the expected output in console.

I would open the issue with reproducible example in the RStudio IDE repo so that they have a look.

I believe this is because cart.1$frame contains some columns which are several dimentions and not one vector.

> dplyr::glimpse(cart.1$frame)
Rows: 3
Columns: 6
$ var    <fct> X2, <leaf>, <leaf>
$ n      <dbl> 500, 250, 250
$ dev    <dbl> 693.1472, 0.0000, 0.0000
$ yval   <fct> a, b, a
$ splits <chr[,2]> "<5.00939", "", "", ">5.00939", "", ""
$ yprob  <dbl[,2]> <matrix[3 x 2]>

This will not be possible to print them as usual table in chunk output. If you remove those columns (it works)

image

Hope it helps

@cderv cderv added the RStudio IDE label Jan 31, 2022
@stgries
Copy link
Author

@stgries stgries commented Jan 31, 2022

Thanks for checking and ok, I'll file a bug report with them.

@stgries stgries closed this as completed Jan 31, 2022
@github-actions
Copy link

@github-actions github-actions bot commented Aug 2, 2022

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
RStudio IDE
Projects
None yet
Development

No branches or pull requests

2 participants