我可以从R studio运行ipython笔记本吗?

时间:2017-10-04 23:57:19

标签: r rstudio

在R中运行分析之前,我想要运行一个ipython笔记本。

我在R笔记本中设置了一个代码块来运行ipython,如下所示

```{python, engine = 'path/to/ipython'}

import os #analogous to library().  Executres

os.chdir('path/to/analysis') #analogous to setwd(). Execures

%runDataExtraction.ipynb  #problem here
```

这是错误

thon: Classes/Stat Comp  File "/var/folders/_1/hdrhn2y9719c6vnr54tsk2tc0000gn/T/RtmpxWbI79/chunk-coded987fa22c02.", line 6
    %run DataExtraction.ipynb
    ^
SyntaxError: invalid syntax

R告诉我最后一行代码中存在语法错误。如果在ipython中运行,代码工作正常。即使是一个重击块也告诉我出了问题。

Chunk是

```{bash}
cd path/to/analysis

jupyter nbconvert --execute DataExtraction.ipynb
```

错误是

/var/folders/_1/hdrhn2y9719c6vnr54tsk2tc0000gn/T/RtmpxWbI79/chunk-coded986d89ee10.: line 3: jupyter: command not found

此错误特别奇怪,因为jupyter命令肯定在命令行中有效。

有没有其他人遇到过类似的问题?

编辑:

很少,但我从ipython运行一个bash命令,一切正常。

```{python, engine.path = 'path/to/ipython'}

import os #analogous to library().  Executres

os.chdir('path/to/analysis') #analogous to setwd(). 

bashCommand = "jupyter nbconvert --execute DataExtraction.ipynb"
import subprocess
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()


```

1 个答案:

答案 0 :(得分:2)

这是我遇到的解决方案

```{python, engine.path = 'path/to/ipython'}

import os #analogous to library().  Executres

os.chdir('path/to/analysis') #analogous to setwd(). 

bashCommand = "jupyter nbconvert --execute DataExtraction.ipynb"
import subprocess
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()


```