在 R-Markdown 文件中编织在命中 python 块时停止而不会出现打印错误 [英] Knitting in R-Markdown file stops without printing error when hitting a python chunk

查看:59
本文介绍了在 R-Markdown 文件中编织在命中 python 块时停止而不会出现打印错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经习惯了 R,但对 R Markdown 还不熟悉.我想在代码中插入 python 块.但是,我无法让它工作.每次我按编织"时,它都会开始编织,直到碰到第一个蟒蛇夹头.然后它只是暂停,不提供错误消息.

I'm used to R, but new to R markdown. I would like to insert python chunks in the code. However, I cannot get it to work. Every time I press "Knit", it starts knitting until it hits the first python chuck. Then it just pauses, without providing an error message.

我已经尝试使用许多示例代码来设置带有来自 Internet 的 reticulate 和 knitr 的 python 引擎,但它们都不起作用.我指定了不同的 python 文件、版本等.似乎我遗漏了一些东西,但我无法弄清楚它是什么.

I've tried using many example codes setting up a python engine with reticulate and knitr from the internet, but none of them work. I've specified different python files, versions, etc. It seems like I'm missing something, but I cannot figure out what it is.

我使用过的代码:

---
title: "Test3"
author: "Stanny"
date: "11 september 2019"
output: pdf_document
#
---

## Set-up

```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(echo = TRUE)
library(reticulate)
use_python("C:\\Users\\STANNY~1\\OneDrive\\envs\\wiki\\python.exe")
```

## A normal R code chunk

```{r}
library(reticulate)
x = 42
print(x)
```

## A Python chunk

```{python}
x = 42 * 2
print(x) 
```

## Modify a Python variable

```{python}
x = x + 18 
print(x)
```

输出:

processing file: test3.Rmd
  |........                                                         |  12%
  ordinary text without R code

  |................                                                 |  25%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |........................                                         |  38%
  ordinary text without R code

  |................................                                 |  50%
label: unnamed-chunk-1
  |.........................................                        |  62%
  ordinary text without R code

  |.................................................                |  75%
label: unnamed-chunk-2 (with options) 
List of 1
 $ engine: chr "python"

推荐答案

遗憾的是无法在 flexdashboard 上运行 python :(
https://github.com/yihui/knitr/issues/1667

saddly is not possible to run python on flexdashboard :(
https://github.com/yihui/knitr/issues/1667

这篇关于在 R-Markdown 文件中编织在命中 python 块时停止而不会出现打印错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆