0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHub actions で R を使ってグラフ画像を作成する(放射線測定マップの作成 Ⅵ)

Last updated at Posted at 2023-12-18

「R のグラフの見栄え調整(放射線測定マップの作成 Ⅳ)」
https://qiita.com/nanbuwks/items/b3b843ea71716d17bfa8

で作ったグラフ画像を作成する仕組みを、

「GitHub Actions を触ってみた(放射線測定マップの作成 Ⅲ)」
https://qiita.com/nanbuwks/items/440a0f34a7ee583d0cae

こちらに反映します。

setup-r を使って R を GitHub Actions にインストール

なんもわからんので、以下のサイトを元に試してみました。

「How to Use GitHub Actions with R to Run Code Automatically」
https://rfortherestofus.com/2023/05/github-actions

ここでつかているのは setup-r というものぽくて、レポジトリはここかな?
https://github.com/r-lib/actions

参考サイトの記述から、以下のように抜き出してみました。

name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  uploadrelease:
    runs-on: ubuntu-latest

    steps:
      - name: Set up R
        uses: r-lib/actions/setup-r@v2

      - name: Install packages
        uses: r-lib/actions/setup-r-dependencies@v2
        with:
          packages: |
            any::tidyverse
            any::googlesheets4
       

実行

滅茶時間がかります。

image.png

なんでこんなに時間がかかるんだ・・・? と処理を見てみたら、ソースをゲットしてビルドしてました。
日に一度、あるいは数時間に一度実行するので14分はまあ許容範囲ですが、サーバに無駄に負荷をかけるのがヤな感じです。

r-actions を試してみる

r を実行する方法はマーケットで他にも公開があったので、こちらを試してみました。
https://github.com/marketplace/actions/r-actions

以下を config.yml に追加します。

      - name: R Build and Checks
        uses: Swechhya/R-actions@v1.2
        with:
          action: 'all'
          needsBioc: false
          buildSubDirectory: './'


エラーが出てしまいました。
image.png

こちらは断念!

setup-r に戻ってパッケージを選ぶ

先の setup-r のスクリプトですが、

            any::tidyverse
            any::googlesheets4

ここがライブラリの指定っぽいです。そして、時間がかかるのは依存しているライブラリをやたらめったらビルドしているためでした。
必要なのは ggplot2 と dplyr なので、以下のように書き換えてみました。

name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  uploadrelease:
    runs-on: ubuntu-latest
    steps:
      - name: Set up R
        uses: r-lib/actions/setup-r@v2

      - name: Install packages
        uses: r-lib/actions/setup-r-dependencies@v2
        with:
          packages: |
            any::dplyr
            any::ggplot2

image.png

おお、このくらいなら全然問題ないですね。

R をインストールする方法でまだ試してないこと

ビルドに時間がかかることを見越して、
「R を Ubuntu でインストールして csv からグラフを書く」
https://qiita.com/nanbuwks/items/f64de73537848a11649d

では旧い R であることを忍んで apt を使ってインストールした環境を元に実験しました。
しかしながら結局 apt は使いませんでした。

また、キャッシュを永続的に行う方法もあるらしいですが、今回はそれを使うほどのことはありませんでした。
https://blog.hoxo-m.com/entry/2020/01/23/171700

グラフを作る

「R のグラフの見栄え調整(放射線測定マップの作成 Ⅳ)」
https://qiita.com/nanbuwks/items/b3b843ea71716d17bfa8

で作った makegraph.R を実行するようにしてみました。

name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  uploadrelease:
    runs-on: ubuntu-latest
    steps:
      - name: Set up R
        uses: r-lib/actions/setup-r@v2

      - name: Install packages
        uses: r-lib/actions/setup-r-dependencies@v2
        with:
          packages: |
            any::dplyr
            any::ggplot2
      - name: Get current daytime
        uses: actions/checkout@v4
      - run: echo "RELEASEDATE=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
      - run: |
           ./getdata.sh
           Rscript makegraph.R test3-100.csv plot2.png
        working-directory: githubaction
      - run: |
          echo "リリース名:$RELEASEDATE"
          git tag $RELEASEDATE
          git push origin $RELEASEDATE
          gh release create $RELEASEDATE --prerelease --notes automake
          gh release upload $RELEASEDATE githubaction/test3-100.csv
          gh release upload $RELEASEDATE githubaction/plot2.png
          gh release edit $RELEASEDATE --prerelease=false --latest
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

plot2.png の作成とリリースへの収録が成功しました。

image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?