2

I ve seen topics asking for a solution to a similar problem, I tried suggested solution.
no success yet. However, I had no issue until yesterday when suddenly this null problem showed up.
I updated everything to the last version and checked for where my python and r miniconda are installed everything seems ok.
I knit the document first also as suggested in other posts.
I m confused what's going on. when I type py$ the drop-down menu shows up suggesting x, but it returns null.

---
title: "test"
author: "ME"
date: '2022-02-23'
output: html_document
---



```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = F, fig.align = 'center')
knitr::knit_engines$set(python = reticulate::eng_python)
library(reticulate)
#library(cleanrmd)

```

```{python}
import numpy as np
import matplotlib.pyplot as matplot
import pandas as pd


x=2
x   ###returns 2
```

```{r}
py$x  #### returns NULL
```
Mathica
  • 1,241
  • 1
  • 5
  • 17

1 Answers1

0

I got a similar problem once. R was calling the python objects, but it failed to generate output when the file was knit to PDF.

I have tried replicating your code, and it gets knit properly in both HTML as well as PDF.

Try updating RStudio.

Also, no need to mention additional parameters in knitr. Just this is also fine.

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

Adding images of the results I got when knit to HTML. I have got them without specifying any engine. enter image description here