knitr:Python的代码外部化
我使用knitr:Python的代码外部化,python,r,knitr,Python,R,Knitr,我使用read\u chunk()从外部源读取R代码。我想知道是否有类似的函数可以将Python代码读入主文档 R works, of course. ```{r test-r, engine='R'} library(knitr) set.seed(123) rnorm(5) ``` Does **knitr** work with Python? Use the chunk option `engine='python'`: ```{r test-python, engine='pyt
read\u chunk()
从外部源读取R
代码。我想知道是否有类似的函数可以将Python
代码读入主文档
R works, of course.
```{r test-r, engine='R'}
library(knitr)
set.seed(123)
rnorm(5)
```
Does **knitr** work with Python? Use the chunk option `engine='python'`:
```{r test-python, engine='python'}
x = 'hello, python world!'
print(x)
print(x.split(' '))
```
我的.Rmd
文档的一些摘录
R works, of course.
```{r test-r, engine='R'}
library(knitr)
set.seed(123)
rnorm(5)
```
Does **knitr** work with Python? Use the chunk option `engine='python'`:
```{r test-python, engine='python'}
x = 'hello, python world!'
print(x)
print(x.split(' '))
```
当然,这适用于Python: 创建包含以下内容的test.py文件:
## @knitr abc
print(1)
在您的RMD文件中:
```{r}
knitr::read_chunk('test.py')
```
```{r abc, engine='python'}
```
对我来说很好。谢谢@JohnColeman的评论
Knitr
可以正确解析Python代码。请查看我的编辑和修改。然而,我对Python
的代码外部化感兴趣。