easystats / insight

:crystal_ball: Easy access to model information for various model objects
https://easystats.github.io/insight/
GNU General Public License v3.0
399 stars 39 forks source link

Display issues with RStudio Visual Editor #644

Closed jmgirard closed 2 years ago

jmgirard commented 2 years ago

I am using RStudio's visual editor to teach novices about R and want to teach them about easystats as well. An issue I'm running into however is that the insight tables are often too wide to display correctly (see below). I know I can use print_md() to get better formatting here but I'd prefer not to have to teach them another function and it also doesn't look great with a dark color theme (see below) although I usually do teach with the default, light background theme.

Open RStudio, create new RMarkdown (or Quarto) document, change to Visual Editor view.

---
output: html_document
---

```{r}
fit <- aov(
  formula = Petal.Length ~ Species,
  data = iris
)
mp <- parameters::model_parameters(fit)
mp
```

```{r}
parameters::print_md(mp)
```

image

strengejacke commented 2 years ago

My best suggestion in this case would be: switch to vscode 😃 The window management is rather different from that in RStudio, but once you get used to it, you can easily (via shortcut) resize panels/windows quickly. I often use this when I get wide tables, then I just press a shortcut and the terminal panel is maximized etc. (You can do this with RStudio as well, but imho less smooth).

Anyway, I don't think that switching is your preferred option. Another way could be to limit the table width. This is not very prominently documented, but below is an example where the table is split at a certain width.

fit <- aov(
  formula = Petal.Length ~ Species,
  data = iris
)
mp <- parameters::model_parameters(fit)
print(mp, table_width = 40)
#> Parameter | Sum_Squares |  df
#> -----------------------------
#> Species   |      437.10 |   2
#> Residuals |       27.22 | 147
#> 
#> Parameter | Mean_Square |       F |      p
#> ------------------------------------------
#> Species   |      218.55 | 1180.16 | < .001
#> Residuals |        0.19 |         |       
#> 
#> Anova Table (Type 1 tests)

Another thing might be the markdown rendering. Not sure if you can easily define the default font color?

(Again, vscode automatically selects a visible color based on the theme you use by default)

image

Finally, you could also try print_html() instead md, which formats the table differently:

image

strengejacke commented 2 years ago

If you prefer to use text output, you could of course rename columns. if column names are making columns too wide:

fit <- aov(
  formula = Petal.Length ~ Species,
  data = iris
)
mp <- parameters::model_parameters(fit)
mp |> datawizard::data_rename(
  pattern = c("Sum_Squares", "Mean_Square"),
  replacement = c("Sum Sq.", "Mean Sq.")
)
#> Parameter | Sum Sq. |  df | Mean Sq. |       F |      p
#> -------------------------------------------------------
#> Species   |  437.10 |   2 |   218.55 | 1180.16 | < .001
#> Residuals |   27.22 | 147 |     0.19 |         |       
#> 
#> Anova Table (Type 1 tests)

or you select only certain columns:

fit <- aov(
  formula = Petal.Length ~ Species,
  data = iris
)
mp <- parameters::model_parameters(fit)
mp |> print(select = c("Parameter", "Mean_Square", "p"))
#> Parameter | Mean_Square |      p
#> --------------------------------
#> Species   |      218.55 | < .001
#> Residuals |        0.19 |       
#> 
#> Anova Table (Type 1 tests)

Does any of these approaches solve your issue?

jmgirard commented 2 years ago

For teaching purposes, I will probably go with either teaching them about print_md() or teaching them print(..., table_width = 40). For my own purposes, I will check out vscode. I already use that for web development so it would be great to consolidate. Do you have any tips/suggested readings on getting started using vscode to do R?

strengejacke commented 2 years ago

Do you have any tips/suggested readings on getting started using vscode to do R?

No, it mostly ends up with the same couple of websites. I have set up a gist, where I try to write down and summarize several things that might be useful when starting VS Code with R: https://gist.github.com/strengejacke/82e8d7b869bd9f961d12b4091c145b88

But back on topic: what about Ctrl+Shift+1 to zoom in/out the source window? That could be a way to fix you problem (or Ctrl+Shift+2 for the console)

jmgirard commented 2 years ago

Actually, this may be the easiest solution for teaching: https://community.rstudio.com/t/visual-editor-too-narrow/112336

menu

fixed

strengejacke commented 2 years ago

Ah, I see. The visual editor isn't affected by resizing the panel.

image

But than we can consider this issue as resolved? I'm not sure what we can further do from our side (except the printing-tips we discussed above)?

bwiernik commented 2 years ago

Personally, one of the first things I taught my students to do was to disable in-line output from notebooks and instead send output to the console. They found that a lot easier to see what the code was doing when they weren't shown output that changed format regularly (eg, text table vs html table)

strengejacke commented 2 years ago

@jmgirard I'm closing this issue as solved. Feel free to reopen if there's something we can do from insight side.