2
1

More than 5 years have passed since last update.

rmarkdownでpythonを実行(Rstudio1.2Preview版,reticulate)

Posted at

取り急ぎのメモ

  • pythonで書いているけれど、Rmarkdownでレポートにしたい
  • Rstudio1.2Previewが出たと聞いたので、飛びついた。
  • reticulateを使ってPythonが使えるらしい。
  • 取り敢えず後でrmdファイルに貼り付けて使えるようにメモ
  • 参考: https://speakerdeck.com/t_usausausa/reticulate-and-rstudio

セットアップ

  • reticulate入れる
  • 使いたいpythonのパスを指定する(今回はanaconda環境)

```{r setup, include=FALSE}
library(reticulate)
use_python("/Users/user/anaconda3/bin/python")
```#これで囲む

pythonのコードで書く

  • チャンクでpython指定してから書く

```{python}
import numpy as np
x=np.array([i for i in range(100)])
y= x**2

import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("darkgrid")
plt.plot(x,y)
plt.show()
```#
  • 取り敢えずこのへんのモジュールは使えるらしい。
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1