Forked from paithiov909/archive-packages-for-ssh.ipynb
Created
November 14, 2021 04:53
-
-
Save kojix2/f535148b99732fe1d8382db9d4761fc8 to your computer and use it in GitHub Desktop.
archive-packages-for-ssh.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "archive-packages-for-ssh.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/paithiov909/6327d6c3cf09c613e51d4659b08b0d48/archive-packages-for-ssh.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "JWA4ZM2jC6QS" | |
}, | |
"source": [ | |
"# Archive R packages for Colaboratory\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "6AP6nYBZU1Pe" | |
}, | |
"source": [ | |
"## セッション切れの防止\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "xs1n3ccvUzDX", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 17 | |
}, | |
"outputId": "47fe9643-b881-4356-dd97-e854bd70892f" | |
}, | |
"source": [ | |
"%%javascript\n", | |
"function ClickConnect(){\n", | |
" console.log(\"Working\");\n", | |
" document.querySelector(\"colab-toolbar-button#connect\").click()\n", | |
"}\n", | |
"/**\n", | |
" * 必要な場合、setIntevalをコメントアウト\n", | |
"*/\n", | |
"// setInterval(ClickConnect,60000)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/javascript": [ | |
"function ClickConnect(){\n", | |
" console.log(\"Working\");\n", | |
" document.querySelector(\"colab-toolbar-button#connect\").click()\n", | |
"}\n", | |
"/**\n", | |
" * 必要な場合、setIntevalをコメントアウト\n", | |
"*/\n", | |
"// setInterval(ClickConnect,60000)" | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "5teOmxdrvMjr" | |
}, | |
"source": [ | |
"## 依存パッケージなどのインストール\n", | |
"\n", | |
"System RequirementsがあるRパッケージは先に必要なものをインストールしておく必要がある。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "HUXd49yW34Mp" | |
}, | |
"source": [ | |
"!sudo add-apt-repository \"deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/\"\n", | |
"!sudo apt -yqq update\n", | |
"\n", | |
"## 要るもの\n", | |
"# !sudo apt -qq -y install default-jdk default-jre\n", | |
"!sudo apt install -yqq --no-install-recommends software-properties-common dirmngr\n", | |
"!sudo apt install -yqq libprotobuf-dev libxml2 libjq-dev libmecab-dev" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "3v0rkNrPvlmX" | |
}, | |
"source": [ | |
"## Rパッケージのインストール\n", | |
"\n", | |
"1. renvでプロジェクトを切る\n", | |
"2. `renv::isolate`でプロジェクトを固定する\n", | |
"3. プロジェクトディレクトリごと圧縮してZIPファイルに固める" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "-yw_QN_V4ThY" | |
}, | |
"source": [ | |
"## rJavaのインストール用のスニペット\n", | |
"import os\n", | |
"os.environ[\"JAVA_HOME\"] = \"/usr/lib/jvm/java-11-openjdk-amd64\"\n", | |
"!R CMD javareconf\n", | |
"\n", | |
"## 新しくディレクトリをつくる\n", | |
"!mkdir workspace\n", | |
"\n", | |
"%load_ext rpy2.ipython" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "QjO5nxLpnlh1" | |
}, | |
"source": [ | |
"%%writefile workspace/pkgs.R\n", | |
"\n", | |
"## ここにCRANから入れたいパッケージを書く\n", | |
"## https://rstudio.github.io/renv/reference/dependencies.html\n", | |
"require(languageserver)\n", | |
"require(httpgd)\n", | |
"require(usethis)\n", | |
"require(devtools)\n", | |
"require(styler)\n", | |
"require(rJava)\n", | |
"require(reticulate)\n", | |
"require(tidyverse)\n", | |
"# require(tidymodels)\n", | |
"# require(ggpubr)\n", | |
"# require(ggcharts)\n", | |
"# require(DataExplorer)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "lDB_s1kHXwbV" | |
}, | |
"source": [ | |
"%%R\n", | |
"## See https://uribo.hatenablog.com/entry/2019/01/11/082000\n", | |
"# Sys.setenv(GITHUB_PAT = \"\")\n", | |
"\n", | |
"install.packages(\"renv\", quiet = TRUE)\n", | |
"\n", | |
"if (requireNamespace(\"renv\", quietly = TRUE)) {\n", | |
"\n", | |
" setwd(\"./workspace\")\n", | |
"\n", | |
" renv::init(bare = TRUE)\n", | |
" renv::hydrate()\n", | |
"\n", | |
" ## `renv::dependencies`で拾えないGitHubなどのパッケージは、ここで個別に指定する\n", | |
" ## See https://rstudio.github.io/renv/reference/install.html\n", | |
" renv::install(\"uribo/zipangu\")\n", | |
" renv::install(\"paithiov909/rjavacmecab\")\n", | |
" # renv::install(\"paithiov909/RcppMeCab@release\")\n", | |
" # renv::install(\"bioc::BiocVersion\")\n", | |
"\n", | |
" renv::snapshot(prompt = FALSE)\n", | |
"\n", | |
" ## パッケージをキャッシュからプロジェクト内にコピーする\n", | |
" ## See https://rstudio.github.io/renv/reference/isolate.html\n", | |
" renv::isolate()\n", | |
"\n", | |
" setwd(\"../\")\n", | |
"}" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "0dyqkqNFwDiz", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "c7ac8d08-e318-4a17-c777-42496bd32048" | |
}, | |
"source": [ | |
"!zip -r workspace workspace > /dev/null\n", | |
"print(os.path.getsize('workspace.zip'))" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"236505648\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "084M0VP-M2Cj" | |
}, | |
"source": [ | |
"## ファイルアップロード" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "SRGbR8XBL-Ih" | |
}, | |
"source": [ | |
"# Import PyDrive and associated libraries.\n", | |
"# This only needs to be done once in a notebook.\n", | |
"from pydrive.auth import GoogleAuth\n", | |
"from pydrive.drive import GoogleDrive\n", | |
"from google.colab import auth\n", | |
"from oauth2client.client import GoogleCredentials\n", | |
"\n", | |
"# Authenticate and create the PyDrive client.\n", | |
"# This only needs to be done once in a notebook.\n", | |
"auth.authenticate_user()\n", | |
"gauth = GoogleAuth()\n", | |
"gauth.credentials = GoogleCredentials.get_application_default()\n", | |
"drive = GoogleDrive(gauth)\n", | |
"\n", | |
"# Create & upload the zip file.\n", | |
"uploaded = drive.CreateFile({ 'title': 'workspace.zip' })\n", | |
"uploaded.SetContentFile('workspace.zip')\n", | |
"uploaded.Upload()\n", | |
"print('Uploaded file with ID {}'.format(uploaded.get('id')))" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment