RstudioからPythonを使う

「とりあえずRstudio上でPythonが少し使えればいい」というライトユーザーなので、簡単そうな方法は以下の通り:

 

まず、reticulateをインストールする


        install.packages("reticulate")
        

 

reticulateを使って、minicondaをインストールする


        reticulate::install_miniconda()
    

 

(minicondaはC:/Users/username/AppData/Local/r-miniconda/にインストールされる)

 

必要なパッケージをインストールする。たとえばpandasをインストールする場合は以下のようにする

 


        reticulate::py_install("pandas")
        

 

File→New file→Python scriptを選択してPythonスクリプトを書く。あとはいつものRstudioの使い方と同じ

 

Minicondaのアップデートは


        reticulate::miniconda_update(path = miniconda_path())
        

 

RstudioでのPythonサポート全般については:

https://support.posit.co/hc/en-us/articles/1500007929061-Using-Python-with-the-RStudio-IDE

reticulateについては:

https://rstudio.github.io/reticulate/

reticulateでの(Pythonの)パッケージインストールについては:

https://rstudio.github.io/reticulate/articles/python_packages.html