rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.68k stars 327 forks source link

Pandas DataFrame printing within a Python chunk in an rmarkdown file. #983

Open hathawayj opened 3 years ago

hathawayj commented 3 years ago

Create an .Rmd file with the following chunks:

---
title: "junk"
author: "J. Hathaway"
date: "3/30/2021"
output: 
  html_document:
    keep_md: true
---

```{r, echo=FALSE, cache=FALSE}
knitr::opts_chunk$set(python.reticulate = TRUE)
library(reticulate)
library(ggplot2)
knitr::opts_chunk$set(engine.path = '/usr/local/bin/python3.8')
import pandas as pd
import altair as alt
import numpy as np
from scipy import stats

flights_url = "https://github.com/byuidatascience/data4python4ds/raw/master/data-raw/flights/flights.csv"

flights = pd.read_csv(flights_url)
flights['time_hour'] = pd.to_datetime(flights.time_hour, format = "%Y-%m-%d %H:%M:%S")
print(flights)
flights


---- 

The previous default would simply print the pandas DataFrame without needing the `print()` statement.  Now it tries to make it an HTML table (second item in the image).  What is the option to stop the auto HTML table?  I don't want to wrap a `print()` statement around every output.

![Screen Shot 2021-03-30 at 9 18 47 PM](https://user-images.githubusercontent.com/6199492/113085698-8dcf5400-919d-11eb-94af-f7f301ea469e.png)
hathawayj commented 3 years ago

Still holding out hope on a response.

kevinushey commented 3 years ago

I think this is an unintended change in the development version of reticulate, probably from this:

https://github.com/rstudio/reticulate/blob/b9c9cd32942e9a2abddabda0a409426fd61b2dba/R/knitr-engine.R#L557-L563

I'll take a look.

hathawayj commented 3 years ago

@kevinushey Looks like that fixed it. I couldn't figure out what was different. Thanks!