简体   繁体   中英

How to use Python block in R markdown?

I am trying to use a Python block in my R markdown document. Below is what I have been trying:


"""{r setup, include=FALSE}
require(reticulate)
use_python("/Users/hyunjindominiquecho/opt/anaconda3", required = T)
"""

"""{python}
# import the necessary python packages
import numpy as np
import pandas as pd
import scipy.stats as st
from rpy2 import robjects
import math
from scipy.optimize import newton
import torch
from pandas import dataframe
from statistics import mean 
"""

but when I try to do this, R studio shows the following error:

Error in system2(command = python, args = paste0("\"", config_script,  : 
  error in running command

How can I resolve this issue? Thank you,

What if you did:

```{python, engine.path = '/Users/hyunjindominiquecho/opt/anaconda3'} 
import sys
print(sys.version)
```

What happens when you only run the first chunk? Do you still get the same error?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM