red_amber 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +75 -0
- data/.devcontainer/devcontainer.json +38 -0
- data/.devcontainer/onCreateCommand.sh +22 -0
- data/.rubocop.yml +11 -5
- data/CHANGELOG.md +141 -17
- data/Gemfile +5 -6
- data/README.ja.md +271 -0
- data/README.md +52 -31
- data/Rakefile +55 -0
- data/benchmark/group.yml +12 -5
- data/doc/Dev_Containers.ja.md +290 -0
- data/doc/Dev_Containers.md +292 -0
- data/doc/qmd/examples_of_red_amber.qmd +4596 -0
- data/doc/qmd/red-amber.qmd +90 -0
- data/docker/Dockerfile +2 -2
- data/docker/Gemfile +8 -3
- data/docker/docker-compose.yml +1 -1
- data/docker/readme.md +5 -5
- data/lib/red_amber/data_frame.rb +78 -4
- data/lib/red_amber/data_frame_combinable.rb +147 -119
- data/lib/red_amber/data_frame_displayable.rb +7 -6
- data/lib/red_amber/data_frame_loadsave.rb +1 -1
- data/lib/red_amber/data_frame_selectable.rb +51 -2
- data/lib/red_amber/data_frame_variable_operation.rb +6 -6
- data/lib/red_amber/group.rb +476 -127
- data/lib/red_amber/helper.rb +26 -0
- data/lib/red_amber/subframes.rb +18 -11
- data/lib/red_amber/vector.rb +45 -25
- data/lib/red_amber/vector_aggregation.rb +26 -0
- data/lib/red_amber/vector_selectable.rb +124 -40
- data/lib/red_amber/vector_string_function.rb +279 -0
- data/lib/red_amber/vector_unary_element_wise.rb +4 -0
- data/lib/red_amber/vector_updatable.rb +28 -0
- data/lib/red_amber/version.rb +1 -1
- data/lib/red_amber.rb +2 -1
- data/red_amber.gemspec +3 -3
- metadata +19 -14
- data/docker/Gemfile.lock +0 -80
- data/docker/example +0 -74
- data/docker/notebook/examples_of_red_amber.ipynb +0 -8562
- data/docker/notebook/red-amber.ipynb +0 -188
@@ -0,0 +1,290 @@
|
|
1
|
+
# 開発コンテナ(Development Containers)の利用
|
2
|
+
|
3
|
+
このリポジトリでは [開発コンテナ(Dev Container)](https://containers.dev/)をサポートしています。
|
4
|
+
これを使うと、ローカルの環境を汚すことなく、RedAmberに必要なツール一式を含んだ環境を準備することができます。この環境には、Ruby、Apache Arrow、RedAmberのソースツリー、GitHub CI、サンプルデータセット、IRubyカーネルを含んだJupyter Labなどが含まれていて、簡単でメンテナンスしやすく、かつ再利用性が高い構成になっています。
|
5
|
+
|
6
|
+
RedAmber用のDev Containerは、`.devcontainer` ディレクトリに必要な設定が書かれています。現在の実装では、Dockerfileを使用せず、Dev Containers用のUbuntuベースイメージに、Dev Container Featuresを使って、Python、GitHub CIの環境を加えて作っています。Ruby は Container ができてから走らせるスクリプトでインストールしています。
|
7
|
+
|
8
|
+
Dockerfileで作るのと比べて、
|
9
|
+
- User周りの設定を自動的にやってくれる
|
10
|
+
- 言語環境をFeatureとして個別に追加することができる
|
11
|
+
- PythonではJupyter Labをオプションとして追加できる
|
12
|
+
- Rubyは`rbenv`をインストールしてあって後から別のバージョンを追加できる
|
13
|
+
- Quartoを動かせる環境を簡単に追加でき、Jupyter notebookのソース管理に利用できる
|
14
|
+
|
15
|
+
等の利点があります。
|
16
|
+
|
17
|
+
ここでは代表的な利用法を2つ紹介します。
|
18
|
+
|
19
|
+
## 1. GitHub Codespacesでクラウド上のVMをブラウザから使う
|
20
|
+
|
21
|
+
### 必要なもの
|
22
|
+
GitHubアカウントにサインインしている必要があります。
|
23
|
+
|
24
|
+
### 注意
|
25
|
+
以下の手順では、Codespacesを起動するあなたのアカウントのクォータを消費します。GitHub Freeに対しては120時間/月・コア(2コアでは60時間)、ストレージ15GB/月が無料で使用できます。使用状況については [Billing and plans](https://github.com/settings/billing)のCodespacesの項を参照してください。
|
26
|
+
|
27
|
+
### 手順
|
28
|
+
- GitHubの[RedAmberのリポジトリ](https://github.com/red-data-tools/red_amber)を開いてください。
|
29
|
+
- 開発を行う場合は、フォークしてご自身のリポジトリを作り、それを開いてください。
|
30
|
+
|
31
|
+
- リポジトリ内の「<>Code」ボタン、「Codespaces」タブにある、「Create codespace on main」ボタンを押して新しいCodespacesを作成してください。
|
32
|
+
* 既にCodespacesがある場合は、該当するコンテナ名をクリックすると再接続できます。
|
33
|
+
- Codespacesの作成には時間がかかります。「View log」をクリックしてぼーっとログを眺めるか、コーヒーを淹れに行くとよいでしょう。
|
34
|
+
* 今後、GitHub Container Registoryにキャッシュを保存して、速く起動できるようにする予定です。
|
35
|
+
- VS Code for ブラウザでリポジトリが開きます。
|
36
|
+
|
37
|
+
動作の確認は、下の[動作の確認](#動作の確認)を参照してください。
|
38
|
+
|
39
|
+
### 詳細
|
40
|
+
より詳しくは、[(GitHub Docs)リポジトリの codespace を作成する](https://docs.github.com/ja/codespaces/developing-in-codespaces/creating-a-codespace-for-a-repository)を参照してください。
|
41
|
+
|
42
|
+
## 2. ローカルにクローンしたリポジトリ―からDev Containerを立ち上げ、VS Codeで使う
|
43
|
+
|
44
|
+
### 必要なもの
|
45
|
+
- Visual Studio Code (October 2020 Release 1.51以降)
|
46
|
+
|
47
|
+
GitHub Codespaces 拡張機能をインストールして、GitHub 資格情報を使用してサインインする必要があります。[GitHub Docs - GitHub Codespaces - 前提条件](https://docs.github.com/ja/codespaces/developing-in-codespaces/using-github-codespaces-in-visual-studio-code#prerequisites)を参照して設定を済ませておいてください。
|
48
|
+
|
49
|
+
- Docker
|
50
|
+
- Windows
|
51
|
+
|
52
|
+
Windows 10 Pro/Enterprise では Docker Desktop 2.0 以降。
|
53
|
+
Windows 10 Home (2004+) では、Docker Desktop 2.3 以降と WSL 2 バックエンド。
|
54
|
+
|
55
|
+
- Mac
|
56
|
+
|
57
|
+
Docker Desktop 2.0 以降
|
58
|
+
|
59
|
+
- Linux
|
60
|
+
|
61
|
+
Docker CE/EE 18.06 以降と Docker Compose 1.21 以降
|
62
|
+
|
63
|
+
- Git
|
64
|
+
|
65
|
+
### 手順
|
66
|
+
|
67
|
+
- ローカルに RedAmberリポジトリのクローンを作成します。
|
68
|
+
|
69
|
+
- 開発を行う場合は、フォークしてご自身のリポジトリを作り、それをクローンしてください。
|
70
|
+
|
71
|
+
```
|
72
|
+
$ git clone https://github.com/red-data-toolsまたは貴方のアカウント名/red_amber.git
|
73
|
+
```
|
74
|
+
または、GitHub CLIで、
|
75
|
+
```
|
76
|
+
$ gh repo clone red-data-toolsまたは貴方のアカウント名/red_amber
|
77
|
+
```
|
78
|
+
とします。
|
79
|
+
|
80
|
+
- 作成したローカルのリポジトリフォルダーをVS Codeで開きます。
|
81
|
+
```
|
82
|
+
$ code red_amber
|
83
|
+
```
|
84
|
+
|
85
|
+
- コンテナーで開く
|
86
|
+
|
87
|
+
今のフォルダーをコンテナーで再度開きます。
|
88
|
+
|
89
|
+
- 左下隅のステータスバーのリモートホスト表示(今はローカルなので「><」の後ろに何もついていない)をクリックするとリモートウィンドウを開くオプションが表示されるので、「コンテナーで再度開く」を選択します。
|
90
|
+
|
91
|
+
- コンテナーの構築が開始されます
|
92
|
+
|
93
|
+
最初の構築には、数分かかることがあります。それ以降の構築は高速になります。
|
94
|
+
構築が完了すると、左下隅のステータスバーのリモートホスト表示にコンテナー名が表示されます。
|
95
|
+
|
96
|
+
## 動作の確認
|
97
|
+
|
98
|
+
### ターミナルでインストールされているツールを確認する
|
99
|
+
|
100
|
+
ターミナルが開いていない場合は、 ``CTRL + ` `` で開いてください。
|
101
|
+
|
102
|
+
下記のコマンドを実行して、ツールがインストール済みであることを確かめてください。
|
103
|
+
|
104
|
+
```shell
|
105
|
+
$ ruby -v --jit
|
106
|
+
$ rbenv versions
|
107
|
+
$ gem -v
|
108
|
+
$ gem list
|
109
|
+
$ bundler -v
|
110
|
+
$ iruby -v
|
111
|
+
|
112
|
+
$ python --version
|
113
|
+
$ pip --version
|
114
|
+
$ pip list
|
115
|
+
$ pipenv --version
|
116
|
+
$ jupyter --version
|
117
|
+
$ jupyter kenelspec list
|
118
|
+
|
119
|
+
$ git -v
|
120
|
+
$ git config user.name
|
121
|
+
$ gh --version
|
122
|
+
```
|
123
|
+
|
124
|
+
ユーザーは、`vscode` という名前で、`uid/gid` はローカルのユーザーと同じになっています。
|
125
|
+
|
126
|
+
```shell
|
127
|
+
$ id
|
128
|
+
```
|
129
|
+
|
130
|
+
### RedAmberのテストを走らせてみる
|
131
|
+
|
132
|
+
```shell
|
133
|
+
$ bundle exec rake
|
134
|
+
```
|
135
|
+
|
136
|
+
### REPLでRedAmberを試す
|
137
|
+
|
138
|
+
プリロードされたデータセットを使って、irbの環境でRedAmberの動作を確認できます。初回はRed Datasetsのデータをロードするため少し時間がかかります。
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
$ rake example
|
142
|
+
|
143
|
+
(snip)
|
144
|
+
|
145
|
+
81: # Welcome to RedAmber example!
|
146
|
+
82: # This environment will offer these pre-loaded datasets:
|
147
|
+
83: # penguins, diamonds, iris, starwars, simpsons_paradox_covid,
|
148
|
+
84: # mtcars, band_members, band_instruments, band_instruments2
|
149
|
+
85: # import_cars, comecome, rubykaigi, dataframe, subframes
|
150
|
+
=> 86: binding.irb
|
151
|
+
|
152
|
+
irb(main):001:0>
|
153
|
+
```
|
154
|
+
|
155
|
+
irbの動作を途中で止めているので、ここで表示されているデータセットが変数に読み込まれています。
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
irb(main):001:0> import_cars
|
159
|
+
=>
|
160
|
+
#<RedAmber::DataFrame : 5 x 6 Vectors, 0x0000000000010914>
|
161
|
+
Year Audi BMW BMW_MINI Mercedes-Benz VW
|
162
|
+
<int64> <int64> <int64> <int64> <int64> <int64>
|
163
|
+
0 2017 28336 52527 25427 68221 49040
|
164
|
+
1 2018 26473 50982 25984 67554 51961
|
165
|
+
2 2019 24222 46814 23813 66553 46794
|
166
|
+
3 2020 22304 35712 20196 57041 36576
|
167
|
+
4 2021 22535 35905 18211 51722 35215
|
168
|
+
```
|
169
|
+
|
170
|
+
名前空間の`RedAmber` はインクルードされています。
|
171
|
+
```ruby
|
172
|
+
irb(main):002:0> VERSION
|
173
|
+
=> "0.5.0"
|
174
|
+
irb(main):003:0> Arrow::VERSION
|
175
|
+
=> "12.0.1"
|
176
|
+
```
|
177
|
+
|
178
|
+
`@`を入力すると最初のブレークポイントに戻ることができます。
|
179
|
+
|
180
|
+
`exit` を入力するとirbを抜けます。
|
181
|
+
|
182
|
+
### Jupyter LabでRedAmberを試す
|
183
|
+
|
184
|
+
Python と IRuby カーネルを持ったJupyter Labをブラウザで起動することができます。
|
185
|
+
|
186
|
+
```shell
|
187
|
+
$ rake jupyter
|
188
|
+
```
|
189
|
+
|
190
|
+
で、ローカルの8888ポートでブラウザが立ち上がります。
|
191
|
+
|
192
|
+
- Notebookフォルダーとして、`doc/notebook` が割り当てられていて、そこには2つの`.ipynb`ファイルがあります。
|
193
|
+
- `red_amber.ipynb` : `README.md` で紹介している操作例。
|
194
|
+
- `examples_of_red_amber.ipynb` : 様々な例を集めたもの。
|
195
|
+
- `require 'red_amber'` は `lib` 以下のソースを読み込んでいます。
|
196
|
+
|
197
|
+
## Quarto によるドキュメント操作
|
198
|
+
|
199
|
+
[Quarto](https://quarto.org/)はオープンソースの科学技術ドキュメントの出版システムです。
|
200
|
+
|
201
|
+
この環境では、RedAmber の動作例を活用するために Quarto CLI を使っています。
|
202
|
+
|
203
|
+
```mermaid
|
204
|
+
---
|
205
|
+
title: Quartoを利用したドキュメント管理
|
206
|
+
---
|
207
|
+
flowchart LR
|
208
|
+
id1["Source management
|
209
|
+
(.qmd)"]
|
210
|
+
id2["Analyze and edit by JupyterLab
|
211
|
+
(.ipynb)"]
|
212
|
+
id3["Publish document
|
213
|
+
(.pdf)"]
|
214
|
+
|
215
|
+
id1 -- convert --> id2 -- convert --> id1
|
216
|
+
id2 -- render --> id3
|
217
|
+
id1 -- render --> id3
|
218
|
+
```
|
219
|
+
|
220
|
+
* Quartoのドキュメント `qmd` 形式でソース管理できます。
|
221
|
+
* `.qmd`ファイルを Jupyter notebook ファイル(`.ipynb`)に変換して、
|
222
|
+
Jupyter Lab上で編集したりデータ解析ができます。
|
223
|
+
* `pdf`形式 に変換することができます。
|
224
|
+
|
225
|
+
### Quarto の動作を確認する
|
226
|
+
|
227
|
+
Quarto のバージョンと動作環境をチェックするには次のようにします。
|
228
|
+
|
229
|
+
```shell
|
230
|
+
$ quarto -v
|
231
|
+
$ quarto check
|
232
|
+
```
|
233
|
+
|
234
|
+
ヘルプを表示するには下記のようにします。
|
235
|
+
|
236
|
+
```shell
|
237
|
+
$ quarto --help
|
238
|
+
$ quarto render --help
|
239
|
+
```
|
240
|
+
|
241
|
+
### ソースからJupyter Notebookを生成する
|
242
|
+
`.qmd`ソースファイルから `.ipynb` を生成するには、
|
243
|
+
|
244
|
+
```shell
|
245
|
+
$ bundle exec rake quarto:convert
|
246
|
+
```
|
247
|
+
とします。`doc/qmd`フォルダー以下にあるqmdソースファイルから `doc/notebook`フォルダーに`ipynb`ノートブックファイルが作成されます。
|
248
|
+
|
249
|
+
より一般的には、
|
250
|
+
|
251
|
+
```shell
|
252
|
+
$ quarto convert ソースファイル.qmd
|
253
|
+
$ quarto convert ソースファイル.qmd --output 出力先ノートブック.ipynb
|
254
|
+
```
|
255
|
+
上の書き方では、出力ファイルはソースファイルの拡張子を `.ipynb`に変えて、ソースファイルと同じディレクトリに保存されます。
|
256
|
+
|
257
|
+
下記のコマンドは、Notebookを作成後、Jupyter Labを開きます。
|
258
|
+
|
259
|
+
```shell
|
260
|
+
$ bundle exec rake jupyter
|
261
|
+
```
|
262
|
+
|
263
|
+
### Jupyter Notebookファイルを`qmd`形式で保存する
|
264
|
+
|
265
|
+
編集したJupyter Notebookをqmd形式に変換できます。
|
266
|
+
|
267
|
+
```shell
|
268
|
+
$ quarto convert ノートブック.ipynb
|
269
|
+
$ quarto convert ノートブック.ipynb --output 出力先ソースファイル.qmd
|
270
|
+
```
|
271
|
+
|
272
|
+
### その他の活用方法
|
273
|
+
|
274
|
+
下記のコマンドは`doc/qmd`フォルダー以下にあるqmdソースファイルを`ipynb`に変換し、実行してpdfを作成します。
|
275
|
+
|
276
|
+
```shell
|
277
|
+
$ bundle exec rake quarto:test
|
278
|
+
```
|
279
|
+
|
280
|
+
下記は`doc/notebook`フォルダーを含めたrakeの生成物を消去します。
|
281
|
+
|
282
|
+
```shell
|
283
|
+
$ rake clean
|
284
|
+
```
|
285
|
+
|
286
|
+
Quartoについてより詳しくは、コマンドラインヘルプ(`quarto --help`)、または[Quarto](https://quarto.org/)公式ページをご覧ください。
|
287
|
+
|
288
|
+
### 謝辞
|
289
|
+
|
290
|
+
Quarto の利用は、西田孝三さんの2022年度のRubyアソシエーション開発助成事業プロジェクト『RubyDataエコシステムへのQuartoの導入とその利用の促進のためのコミュニティ活動』 がきっかけとなりました。この場をお借りして感謝申し上げます。
|
@@ -0,0 +1,292 @@
|
|
1
|
+
# How to use Development Containers in RedAmber
|
2
|
+
|
3
|
+
We support [Development Container](https://containers.dev/) in this repository.
|
4
|
+
You can prepare a container as a full-featured development environment for RedAmber. Dev Containers allow you to encapsulate Ruby, Apache Arrow, RedAmber with source tree, GitHub CLI, sample datasets and Jupyter Lab with IRuby kernel. You don't need to worry about the change of your local environment.
|
5
|
+
|
6
|
+
`.devcontainer` directory in this repository includes settings of Dev Container for RedAmber. We don't use Dockerfile here, based on Ubuntu image for Dev Container, Python and GitHub CLI tools using Dev Container Features. I think this style has simplicity, maintainability, and reusability. Ruby is added after the container is created by script.
|
7
|
+
|
8
|
+
It has some benefits below compared to make dev environment by Dockerfile;
|
9
|
+
|
10
|
+
1) It automatically makes user setting with same UID/GID as local user.
|
11
|
+
2) Additional tools can be introduced by `Dev Container Features`.
|
12
|
+
3) Ruby Feature includes `rbenv` and it is easy to add another version afterwards.
|
13
|
+
4) Python Feature includes Jupyter Lab as an option.
|
14
|
+
5) Quarto is introduced. It converts Jupyter notebook from/to qmd file and it is useful to manage notebook in the source tree.
|
15
|
+
|
16
|
+
We will show 2 examples here.
|
17
|
+
|
18
|
+
## 1. GitHub Codespace in cloud from browser
|
19
|
+
|
20
|
+
### Prerequisite
|
21
|
+
|
22
|
+
You need to sign in GitHub Account.
|
23
|
+
|
24
|
+
### Notice
|
25
|
+
|
26
|
+
You will consume your Codespace quota of your account in the step below. For GitHub Free, you can use 120 hours per month per core (it means 60 hours per month for 2 cores VM) and have a storage with 15 GB per month for free. You can check your usage from `Codespaces` section in [Billing and plans](https://github.com/settings/billing).
|
27
|
+
|
28
|
+
### Procedures
|
29
|
+
- Open the [repository of RedAmber](https://github.com/red-data-tools/red_amber) in GitHub.
|
30
|
+
- If you are going to develop RedAmber, you should fork it and open your forked repository to push PR later.
|
31
|
+
|
32
|
+
- Push `<>Code` button, select `Codespaces` tab, push `Create codespace on main` button to create new Codespace.
|
33
|
+
* You can re-connect existing Codespace if you already have there.
|
34
|
+
- Creating Codespace takes time. You can click `View log` to browse log running or have a coffee to wait.
|
35
|
+
* I am planning to improve building process to save cache in GitHub Container Registory.
|
36
|
+
|
37
|
+
- VS Code for browser will open the repository in the remote container.
|
38
|
+
|
39
|
+
Please refer [Operations](#operations) to use the environment.
|
40
|
+
|
41
|
+
### Details
|
42
|
+
Please see [(GitHub Docs)Creating a codespace for a repository](https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace-for-a-repository) for detail.
|
43
|
+
|
44
|
+
## 2. Start Dev Container from the local repository, and use it from VS Code
|
45
|
+
|
46
|
+
### Prerequisites
|
47
|
+
- Visual Studio Code (October 2020 Release 1.51+)
|
48
|
+
|
49
|
+
You need to install GitHub Codespaces extention, and sign into GitHub Codespaces with your GitHub credentials. Please see [GitHub Docs - GitHub Codespaces - Prerequisites](https://docs.github.com/en/codespaces/developing-in-codespaces/using-github-codespaces-in-visual-studio-code#prerequisites) and prepare settings.
|
50
|
+
|
51
|
+
- Docker
|
52
|
+
- Windows
|
53
|
+
|
54
|
+
In Windows 10 Pro/Enterprise, Docker Desktop 2.0+
|
55
|
+
In Windows 10 Home (2004+), Docker Desktop 2.3+ and WSL 2 backend.
|
56
|
+
|
57
|
+
- Mac
|
58
|
+
|
59
|
+
Docker Desktop 2.0+
|
60
|
+
|
61
|
+
- Linux
|
62
|
+
|
63
|
+
Docker CE/EE 18.06+ and Docker Compose 1.21+
|
64
|
+
|
65
|
+
- Git
|
66
|
+
|
67
|
+
### Procedures
|
68
|
+
|
69
|
+
- Create a local clone of RedAmber repository.
|
70
|
+
|
71
|
+
- If you are going to develop RedAmber, make a fork and clone it.
|
72
|
+
|
73
|
+
```
|
74
|
+
$ git clone https://github.com/(red-data-tools or your account name)/red_amber.git
|
75
|
+
```
|
76
|
+
|
77
|
+
Alternatively using GitHub CLI,
|
78
|
+
|
79
|
+
```
|
80
|
+
$ gh repo clone (red-data-tools or your account name)/red_amber
|
81
|
+
```
|
82
|
+
|
83
|
+
- Open local repo folder by VS Code.
|
84
|
+
|
85
|
+
```
|
86
|
+
$ code red_amber
|
87
|
+
```
|
88
|
+
|
89
|
+
- Re-open by container
|
90
|
+
|
91
|
+
Re-open current folder by container.
|
92
|
+
|
93
|
+
- Click remote host indicator in the left bottom corner, then options to open remote windows will open. Choose 'reopen by container'.
|
94
|
+
|
95
|
+
- Building of container will start.
|
96
|
+
|
97
|
+
It takes time for first building. If it is finished, container name will be displayed on the remote host indicator.
|
98
|
+
|
99
|
+
## Operations
|
100
|
+
|
101
|
+
### Check installed tools by terminal
|
102
|
+
|
103
|
+
If you don't have the terminal open, open it with ``CTRL + ` ``.
|
104
|
+
|
105
|
+
Run these command to check these tools are installed.
|
106
|
+
|
107
|
+
```shell
|
108
|
+
$ ruby -v --jit
|
109
|
+
$ rbenv versions
|
110
|
+
$ gem -v
|
111
|
+
$ gem list
|
112
|
+
$ bundler -v
|
113
|
+
$ iruby -v
|
114
|
+
|
115
|
+
$ python --version
|
116
|
+
$ pip --version
|
117
|
+
$ pip list
|
118
|
+
$ pipenv --version
|
119
|
+
$ jupyter --version
|
120
|
+
$ jupyter kenelspec list
|
121
|
+
|
122
|
+
$ git -v
|
123
|
+
$ git config user.name
|
124
|
+
$ gh --version
|
125
|
+
```
|
126
|
+
|
127
|
+
The user name is `vscode` in this environment. `uid` and `gid` are the same as local user.
|
128
|
+
|
129
|
+
```shell
|
130
|
+
$ id
|
131
|
+
```
|
132
|
+
|
133
|
+
### Run tests of RedAmber
|
134
|
+
|
135
|
+
```shell
|
136
|
+
$ bundle exec rake
|
137
|
+
```
|
138
|
+
|
139
|
+
### Try RedAmber in REPL
|
140
|
+
|
141
|
+
You can try RedAmber in `irb` using pre loaded datasets. It takes time in the first run to load the datasets from Red Datasets.
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
$ rake example
|
145
|
+
|
146
|
+
(snip)
|
147
|
+
|
148
|
+
81: # Welcome to RedAmber example!
|
149
|
+
82: # This environment will offer these pre-loaded datasets:
|
150
|
+
83: # penguins, diamonds, iris, starwars, simpsons_paradox_covid,
|
151
|
+
84: # mtcars, band_members, band_instruments, band_instruments2
|
152
|
+
85: # import_cars, comecome, rubykaigi, dataframe, subframes
|
153
|
+
=> 86: binding.irb
|
154
|
+
|
155
|
+
irb(main):001:0>
|
156
|
+
```
|
157
|
+
|
158
|
+
This code stops in the code by `binding.irb`, you have some datasets in local variables.
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
irb(main):001:0> import_cars
|
162
|
+
=>
|
163
|
+
#<RedAmber::DataFrame : 5 x 6 Vectors, 0x0000000000010914>
|
164
|
+
Year Audi BMW BMW_MINI Mercedes-Benz VW
|
165
|
+
<int64> <int64> <int64> <int64> <int64> <int64>
|
166
|
+
0 2017 28336 52527 25427 68221 49040
|
167
|
+
1 2018 26473 50982 25984 67554 51961
|
168
|
+
2 2019 24222 46814 23813 66553 46794
|
169
|
+
3 2020 22304 35712 20196 57041 36576
|
170
|
+
4 2021 22535 35905 18211 51722 35215
|
171
|
+
```
|
172
|
+
|
173
|
+
The namespace `RedAmber` is included.
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
irb(main):002:0> VERSION
|
177
|
+
=> "0.5.0"
|
178
|
+
irb(main):003:0> Arrow::VERSION
|
179
|
+
=> "12.0.1"
|
180
|
+
```
|
181
|
+
|
182
|
+
You can return to the first breakinng point by hitting `@`.
|
183
|
+
|
184
|
+
You can exit irb by `exit`.
|
185
|
+
|
186
|
+
### Try RedAmber in Jupyter Lab
|
187
|
+
|
188
|
+
You can try Jupyter Lab with Python and IRuby kernels in your browser.
|
189
|
+
|
190
|
+
```shell
|
191
|
+
$ rake jupyter
|
192
|
+
```
|
193
|
+
|
194
|
+
- `doc/notebook` is allocated as notebook folder. There are 2 files in it.
|
195
|
+
- `red_amber.ipynb` : Examples in `README.md`.
|
196
|
+
- `examples_of_red_amber.ipynb` : Hundreds examples of RedAmber.
|
197
|
+
- `require 'red_amber'` will load from source directory `lib`.
|
198
|
+
|
199
|
+
## Document authoring by Quarto
|
200
|
+
|
201
|
+
[Quarto](https://quarto.org/) is an open-source scientific and technical publishing system.
|
202
|
+
We use Quarto CLI to show usage examples of RedAmber.
|
203
|
+
|
204
|
+
```mermaid
|
205
|
+
---
|
206
|
+
title: Document management with Quarto
|
207
|
+
---
|
208
|
+
flowchart LR
|
209
|
+
id1["Source management
|
210
|
+
(.qmd)"]
|
211
|
+
id2["Analyze and edit by JupyterLab
|
212
|
+
(.ipynb)"]
|
213
|
+
id3["Publish document
|
214
|
+
(.pdf)"]
|
215
|
+
|
216
|
+
id1 -- convert --> id2 -- convert --> id1
|
217
|
+
id2 -- render --> id3
|
218
|
+
id1 -- render --> id3
|
219
|
+
```
|
220
|
+
|
221
|
+
* We can manage the source of the Jupyter notebook by Quarto's markdown format `qmd`.
|
222
|
+
* We can convert a `.qmd` file to a Jupyter notebook file (`.ipynb`) and will be able to edit it or make analysis on Jupyter Lab.
|
223
|
+
* We can render `.qmd` or `.ipynb` files to `.pdf`.
|
224
|
+
|
225
|
+
### To show the information of Quarto
|
226
|
+
|
227
|
+
Try below to show version and verify correct functioning of Quarto installation.
|
228
|
+
|
229
|
+
```shell
|
230
|
+
$ quarto -v
|
231
|
+
$ quarto check
|
232
|
+
```
|
233
|
+
|
234
|
+
To show help,
|
235
|
+
|
236
|
+
```shell
|
237
|
+
$ quarto --help
|
238
|
+
$ quarto render --help
|
239
|
+
```
|
240
|
+
|
241
|
+
### Convert qmd file to Jupyter Notebook
|
242
|
+
|
243
|
+
To convert `.qmd` source file to `.ipynb`,
|
244
|
+
|
245
|
+
```shell
|
246
|
+
$ bundle exec rake quarto:convert
|
247
|
+
```
|
248
|
+
|
249
|
+
This command will create `ipynb` notebooks from `doc/qmd` and save them to `doc/notebook`.
|
250
|
+
|
251
|
+
In more general,
|
252
|
+
|
253
|
+
```shell
|
254
|
+
$ quarto convert source_file.qmd
|
255
|
+
$ quarto convert source_file.qmd --output Notebook.ipynb
|
256
|
+
```
|
257
|
+
|
258
|
+
The first one will output `source_file.ipynb` file in the same directory.
|
259
|
+
|
260
|
+
Command below will convert qmd_document files in `doc/qmd` to `.ipynb` files and save them to `doc/notebook` . Then open `doc/notebook` with Jupyter Lab.
|
261
|
+
|
262
|
+
```shell
|
263
|
+
$ bin/jupyter
|
264
|
+
```
|
265
|
+
|
266
|
+
### Convert Jupyter Notebook to `qmd`
|
267
|
+
|
268
|
+
You can convert Notebook file to qmd file.
|
269
|
+
|
270
|
+
```shell
|
271
|
+
$ quarto convert notebook.ipynb
|
272
|
+
$ quarto convert notebook.ipynb --output output_source_file.qmd
|
273
|
+
```
|
274
|
+
|
275
|
+
### Others
|
276
|
+
|
277
|
+
To render Notebook files in `doc/qmd` to pdf,
|
278
|
+
|
279
|
+
```shell
|
280
|
+
$ bundle exec rake quarto:test
|
281
|
+
```
|
282
|
+
To clear `doc/notebook` (and all the generated artifacts by rake),
|
283
|
+
|
284
|
+
```shell
|
285
|
+
$ rake clean
|
286
|
+
```
|
287
|
+
|
288
|
+
To know more about Quarto, see command line help by `quarto --help`, or visit [Quarto](https://quarto.org/) web.
|
289
|
+
|
290
|
+
### Thanks
|
291
|
+
|
292
|
+
As for the use of Quarto, I started to try after the Kozo Nishida's work with Ruby Association Grant 2022 "Introducing Quarto into the RubyData ecosystem and promoting the combination to the Ruby community". I would like to take this opportunity to thank him.
|