-
Notifications
You must be signed in to change notification settings - Fork 18
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
Make output friendly to Quarto documents when there is any R code being executed in the .qmd file too #207
Comments
Hello, Thanks for your positive feedback and clear suggestion! Do you know of any examples of how this is done with other Python packages? I'm trying to work out how to ensure that outputs rendered in quarto do this. BTW the skimpy website is generated via Quarto and the rendering seems to work there, so wondering if this could be more to do with Quarto settings than the Skimpy package? However, it would be great if it could 'just work'. |
I believe the output is created using a special formatting method when
knitr/quarto/rmarkdown is detected:
- Documentation: https://rdrr.io/cran/skimr/man/knit_print.html
- Actual code:
https://github.com/ropensci/skimr/blob/2a23e90b763b524f84222f925c530a42b9601a19/R/skim_print.R
I'm not entirely sure how they detect that code is run in a knitr chunk,
though - my guess would be that knitr/quarto/markdown uses a hook that
invokes the method? (Sorry, I'm not a python whiz, my expertise is more on
the R side, so I'm not even sure if I'm using the pythonic words for such
concepts).
There's also a method for Jupyter notebooks that wraps the output in a
print statement so that what the chunk shows is the output and not the
object data.
The formatting for skimpy works well by itself, I just was noticing the
difference in R and python in that the tables are rendered in skimpy using
text-style formatting, where the R tables are rendered using the
markdown-specific
formatting <https://quarto.org/docs/authoring/tables.html> that results in
e.g. striped tables. I rather like both effects, but it would be nice to
have consistent formatting, and if the user has other markdown-style
striped tables in the document, the skimpy default formatting can look a
bit out of place, if that makes sense. Pandas includes a .to_markdown()
<https://blog.ouseful.info/2021/09/22/simple-markdown-table-output-from-pandas-dataframes/>
method for tabular information, so it may be as simple as just breaking up
the generic output into 3 tables as is done in skimR, and then wrapping
them in .to_markdown().
Hopefully that helps!
…On Wed, Jun 22, 2022 at 7:10 AM aeturrell ***@***.***> wrote:
Hello,
Thanks for your positive feedback and clear suggestion! Do you know of any
examples of how this is done with other Python packages? I'm trying to work
out how to ensure that outputs rendered in quarto do this. BTW the skimpy
website <https://aeturrell.github.io/skimpy/> is generated via Quarto and
the rendering seems to work there, so wondering if this could be more to do
with Quarto settings than the Skimpy package? However, it would be great if
it could 'just work'.
—
Reply to this email directly, view it on GitHub
<#207 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQHKFNS42X4B4EFEOO5K33VQL7C7ANCNFSM5YYBWQQQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Not made much progress on this yet, but confirmed that a Python quarto session works with the following ---
title: "Example Report"
author: "Joan Robinson"
format: html
toc: true
number-sections: true
jupyter: python3
---
## Test using skimpy in a Python session
```{python}
from skimpy import skim, generate_test_data
df = generate_test_data()
skim(df)
``` And that as soon as a single executable R chunk is added, the output switches to markdown. So the output would need to recognise that it's in a QMD file where R is also being run. Here's a reprex of where an R chunk being present causes the markdown output to occur from the Python chunk: ---
title: "Example Report"
author: "Joan Robinson"
format: html
---
## Test using skimpy in a Python session
Here is using skimpy
```{r}
data(mtcars)
```
```{python}
from skimpy import skim, generate_test_data
df = generate_test_data()
skim(df)
``` |
Some users prefer markdown-like output (which can be rendered to usual tables) for others the "classical" output (as it is now) is preferred. So after the feature requested in this issue is implemented, please, leave an option (argument, etc.) to have the output in Quarto / R markdown / |
The ideal here would be to be able to recognise when a Quarto document has some R chunks and switch to the markdown output (instead of "classic") automatically in that situation. I think I'd need to talk to someone who has worked on Quarto to understand if this is possible and how to do it. |
It would be helpful to have a quarto-friendly output option, so that tables generated from skim render in markdown instead of rendering as code-like objects.
For instance, a file like this, with a python skim(df) statement and an R skim(df) statement
(you'll have to add the qmd extension, github won't let me upload a qmd file)
test.qmd
renders as
Thank you for making this package, btw - it has made it much easier to teach my students R and python simultaneously when there are so many packages that have parallel functions and syntax between them.
The text was updated successfully, but these errors were encountered: