r语言 - knitr:Python的代码外部化



我使用 read_chunk()从外部源读取R代码。我想知道是否有类似的函数将Python代码读取到主文档中。

我的.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'}
```

对我来说很好。

最新更新