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

coexistence of R and Python gives me inconsistent table renderings #3457

Open
4 tasks done
aborruso opened this issue Nov 25, 2022 · 6 comments
Open
4 tasks done

coexistence of R and Python gives me inconsistent table renderings #3457

aborruso opened this issue Nov 25, 2022 · 6 comments
Labels
enhancement New feature or request tables Issues with Tables including the gt integration upstream Bug is in upstream library
Milestone

Comments

@aborruso
Copy link
Contributor

aborruso commented Nov 25, 2022

Bug description

Hi,
I have really strange table rendering problems.

My code is the one below. If I render it, the python ouput table is printed as plain text

image

If I change {r} in {{r}}, and render again the file, I have the correct rendering of the python ouput table

image

It seems to me that something does not work properly, but it seems to me that the code has no errors.

I'm using quarto 1.3.21, in debian 11 (inside WSL2).

Thank you

---
title: "tables test"
format: html
---

```{python}
import pandas as pd

df = pd.read_csv("input.csv")
df
```


```{r}
library(tidyverse)
data <- read_csv('input.csv')
knitr::kable(data)
```
year,i,v
2016,F,0.9599716561118586
2016,G,0.0382418519682473
2016,C,0.0012657864805693667
2016,W,1.2161279236855405e-05
2016,S,4.5402109150926846e-05

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.
@aborruso aborruso added the bug Something isn't working label Nov 25, 2022
@cscheid
Copy link
Collaborator

cscheid commented Nov 27, 2022

This is probably an inconsistency between the table rendering choices among the jupyter and knitr engines, especially in the presence of multiple-language configurations. If you must have perfectly consistent table rendering output, make sure your table libraries all emit pure markdown. (You can check by keep-md: true and inspecting the output.)

@cscheid cscheid added enhancement New feature or request tables Issues with Tables including the gt integration and removed bug Something isn't working labels Nov 27, 2022
@cscheid cscheid added this to the Future milestone Nov 27, 2022
@aborruso
Copy link
Contributor Author

If you must have perfectly consistent table rendering output, make sure your table libraries all emit pure markdown.

No they do not emit pure markdown.

The first one, the python output, it's simply text.
But if I remove the r output, without changing anything in the python code, I have a markdown table output.

In my opinion this inconsistency is a bug. Unfortunately I don't know how to help you with coding, otherwise I would try to do it

Thank you @cscheid

::: {.cell-output .cell-output-stdout}
```
   year    i         v
0  2016    F  0.959972
1  2016    G  0.038242
2  2016  NaN  0.001266
3  2016    W  0.000012
4  2016    S  0.000045
```
:::
:::

::: {.cell}

```{.r .cell-code}
library(tidyverse)
data <- read_csv('input_s.csv')
knitr::kable(data)
```

::: {.cell-output-display}
| year|i  |         v|
|----:|:--|---------:|
| 2016|F  | 0.9599717|
| 2016|G  | 0.0382419|
| 2016|NA | 0.0012658|
| 2016|W  | 0.0000122|
| 2016|S  | 0.0000454|
:::
:::

@cscheid
Copy link
Collaborator

cscheid commented Dec 6, 2022

The issue here is that python, in a a page with two languages (python+r), gets executed through reticulate+knitr, while a page with a single language gets executed through jupyter.

In order for this to be fixed, reticulate needs to change the way they produce output from the default printing method from Pandas. It appears that right now they're emitting pure text, but it should emit markdown if inside knitr.

@cscheid
Copy link
Collaborator

cscheid commented Dec 6, 2022

This is currently an open issue for this in reticulate: rstudio/reticulate#783. I'm currently in contact with the reticulate devs, so no need to follow up there.

@cscheid cscheid modified the milestones: Future, v1.3 Dec 6, 2022
@aborruso
Copy link
Contributor Author

aborruso commented Dec 6, 2022

Thank you very much.

For this kind of issues probably I have created some noise here and in discussions.

And I'm happy that it has some sense.

Please forgive me for the confusion I made

@cderv
Copy link
Collaborator

cderv commented Jul 19, 2023

Just an update on how reticulate behave:

Regarding how pandas table are handled, they do catch Pandas table and print them asis without processing.
This happens instead of usual behavior to call the internal _repr_html_ method.
https://github.com/rstudio/reticulate/blob/a1d7f7f573f652212bc2c72c39317340e6d8b511/R/knitr-engine.R#L576-L580

Changing that in reticulate would produce the same table in the intermediate .md and same processing by Quarto.

@cscheid cscheid modified the milestones: v1.4, v1.5 Dec 13, 2023
@cscheid cscheid modified the milestones: v1.5, Future Feb 12, 2024
@rich-iannone rich-iannone removed their assignment Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tables Issues with Tables including the gt integration upstream Bug is in upstream library
Projects
None yet
Development

No branches or pull requests

4 participants