LoginSignup
24

More than 5 years have passed since last update.

ディープラーニングをR言語でやるときに,Google ColaboratoryのGPUを使いたくなるかと思います.そのためには,Google ColaboratoryでR言語を使えるように設定しないといけません.
本記事ではその方法を紹介します.

こちらの英語のサイトを参考にしました.

まず,ノートブックに以下をコピペします.

!apt-get install libssl-dev > /dev/null
!wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x ./Miniconda3-latest-Linux-x86_64.sh
!./Miniconda3-latest-Linux-x86_64.sh -b -p /conda  > /dev/null 2>&1 
!/conda/bin/conda install -c r r-rstan r-irkernel gxx_linux-64 -y -q > /dev/null 2>&1
!/conda/bin/R -e "IRkernel::installspec(name = 'python3', displayname = 'R', user = FALSE)"  > /dev/null 2>&1
!mkdir /root/.R/
!echo "CXX14FLAGS=-O3 -mtune=native -march=native -Wno-ignored-attributes -Wno-deprecated-declarations" > /root/.R/Makevars
import os
os._exit(00)

ただし,上から6行目の'python3'はpython2系を使っている場合,'python2'に直す必要があります.

これを実行すると,数分後に以下のような画面が表示されます.
google_colab.PNG

「不明な理由により,セッションがクラッシュしました」と表示されるはずです.

次に,上部の「ランタイム」から「セッションの管理」を選びます.
アクティブなセッション.PNG
すると,アクティブなセッションの一覧が出ますので,「終了」ボタンを押します.

この後に,ノートブックを再接続すればR言語を使うことができます.
例えば次のようなhelloと言うRの関数も動きます.
hello.PNG

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
24