LoginSignup
1
2

More than 3 years have passed since last update.

z/OSにRを導入してみた

Last updated at Posted at 2017-02-14

はじめに

Rocket社というところがOpen Source Languages and Tools for z/OS というのを提供してくれてまして、オープンソースをz/OS上(基本的にUnix System Service上)で動くようにポーティングしてくれてるんですねぇ。
z/Linux版でなく、z/OS版ですよ! ステキです。

Open Source Languages and Tools for z/OS

さて、上のサイトをみてみると、Perl, PHP, Pythonと並んで、なんとRも提供されています!しかも最新の3.3.2が提供されました。
これらのツールは無償で入手できちゃいます。
ということで、z/OS上でRを導入してみましたので、作業ログを記載します。z/OS環境ですので当然インターネットに直接つながる訳もなく、いわゆるオフラインでのインストールということになります。


※2018/06/19追記
なんと、気づいたらRocket SoftwareのProduct ListからR for z/OSが消えている!
うーむ、残念。Pythonの方に比重を置いているっぽいな...

https://www.rocketsoftware.com/zos-open-source

関連記事

インフラ屋さんのためのR言語: 環境構築編
オフラインでのR環境構築 on RHEL
z/OSにRを導入してみた <= 当記事
インフラ屋さんのためのR言語: プログラミング編
R Markdownによるレポート生成
R MarkdownのHTMLレポートをブラッシュアップ
R - ShinyによるWebアプリケーション作成: 基礎編
R - ShinyによるWebアプリケーション作成: shinydashboard編
R - ShinyによるWebアプリケーション作成Tips: shinydashboardでの画面遷移制御
R - ShinyによるWebアプリケーション作成Tips: UIオブジェクトの動的制御
R - Shinyアプリ/管理サーバー テンプレート
R - ShinyアプリでJリーグの勝点推移グラフを作成してみた

Rの入手

上のサイトからR3.3.2にダウンロードボタンを選択すると、名前やら住所やら会社名やらを入力するフォームが出てくるので、必須項目を入力して"Request Download Link"をクリックすると、指定したメールアドレスに、ダウンロード用のURLが送られてきます。
そこからRが入手できます。
USS上で動かすものなので、SMP/Eでの導入とかは不要です。ただ、基本tar.gzで圧縮されているので、解凍用にgzipも合わせて入手しましょう。これもRocket社の同じサイトから入手できます(上のサイトのToolというタブにあります)。

オープンソースでお手軽に無償で入手できるのはよいのですが、残念ながらドキュメントがあまりしっかりしていません。一旦解凍しないとREADMEとか見られなかったし...

r-3.3.2_b0005.170107.tar.gzというのがダウンロードできるのですが、これをUSSにもっていって、別途入手したgzipでgunzipしてみるけどどうもうまくいきませんでした。仕方ないので、一旦Windowsでunzipだけして、(ファイル名が文字化け状態になるので適当に直して)、tarファイルにしてからそれをUSSにFTPし、そこでtarで解凍する、ということをしました。

そこでできあがるのが、
- 各種README
- python-r-devel_b0005.161122.tar.gz
- r-3.3.2_b0005.161122.tar.gz

こんな感じです。
python-r-develというのは開発環境っぽいです。

README_FIRST.ASCII
As with this file, the *.ZOS files are all text files encoded in ASCII.
If you did not untar using UX options you will need to manually tag these text files.

This distribution is made up of two tars: python-r-devel and r-3.3.2.
Both must be installed.  Start by installing python-r-devel, then install r-3.3.2.
Detailed instructions can be found in the corresponding README files.

python-r-develインストール

python-r-develインストールしてから、r-3.3.2をインストールする必要があるらしい。
ふむふむ。

PYTHON_R_DEVEL_README.ZOS
This is a release of a beta version of a port of many packages to z/OS.
These packages might be required in order
to build, install, or run R or Python packages.
This release was built on a z/OS 2.2 system.
Everything is built 64 bit and in ASCII mode.
This distribution was created on "2016-11-22-10-06" from the contents
of "/u/pdfand/dev/opensource" on system RS28.

After being unpacked, this release will occupy 614488 KB.


UNPACK
The recommended way to unpack this tar.gz is:
First, cd to the directory which will contain the distribution.
Then run the command below, but if the dist.tar.gz file is in a different
directory, be sure to put that directory in front of dist.tar.gz.
/bin/cat dist.tar.gz | gunzip -c | /bin/tar xUXof -
Please note that the uppercase U and X and the lowercase o are required.

CHECK
Change your working directory to the directory where you unpacked the files,
then run these two commands:
/bin/find . -type f -filetag u -print | /bin/wc -l
/bin/find . -type f -print | /bin/wc -l
The first result is the count of untagged files,
and the second is the total number of files.
Almost all the files should be tagged.
If not, you probably forgot to use UX in the unpacking phase,
and you must follow the UNPACK instructions again.
...

これに沿ってインストール進めてみる。
/usr/lpp/R332/python-r-devel/に展開することにします。

[CICS004@EPLEX1:/V1R11/usr/lpp/R332/python-r-devel] gunzip python-r-devel_b0005.161122.tar.gz
[CICS004@EPLEX1:/V1R11/usr/lpp/R332/python-r-devel] ls
python-r-devel_b0005.161122.tar
[CICS004@EPLEX1:/V1R11/usr/lpp/R332/python-r-devel] tar -xUXof python-r-devel_b0005.161122.tar
...

[CICS004@EPLEX1:/V1R11/usr/lpp/R332/python-r-devel] find . -type f -filetag u -print | wc -l
     57
[CICS004@EPLEX1:/V1R11/usr/lpp/R332/python-r-devel] find . -type f -print | wc -l
  17723

[CICS004@EPLEX1:/V1R11/usr/lpp/R332/python-r-devel] ./bin/fix-distribution

READMEの記述に沿って .profile設定

.profile
# env for python-devel
export BD=/usr/lpp/R332/python-r-devel
export PATH=/usr/lpp/R332/gzip:$BD/bin:$PATH
export LIBPATH=$BD/lib:$LIBPATH
export PKG_CONFIG_PATH=$BD/lib/pkgconfig:$BD/share/pkgconfig
export CURL_CA_BUNDLE=$BD/etc/ssl/cacert.pem
export FFI_LIB=$BD/lib/ffi
export X11_DIST=$BD
export DEVEL_DIST=$BD

Rインストール

R_README.ZOS
This is a beta release of R 3.3.1.

This release of R contains the packages:
BH DBI Formula Hmisc IRdisplay IRkernel KernSmooth MASS Matrix R.methodsS3 R.oo R.utils 
R6 RColorBrewer Rcpp abind acepack assertthat base base64enc bitops boot caTools chron 
class cluster coda codetools colorspace compiler crayon curl data.table datasets devtools 
dichromat digest dplyr evaluate flexdashboard foreign formatR ggplot2 gistr git2r grDevices 
graphics grid gridExtra gtable hexbin highr htmltools htmlwidgets httpuv httr jsonlite knitr 
labeling lattice latticeExtra lavaan lazyeval log4r magrittr maps markdown memoise methods 
mgcv mime minqa mnormt munsell nlme nnet openssl parallel pbdZMQ pbivnorm plotrix plyr pryr 
quadprog rbenchmark rbokeh repr reshape2 rmarkdown rpart rstudioapi rzmq scales shiny spatial
splines stats stats4 stringi stringr survival tcltk tibble tools utils uuid whisker withr xml2 
xtable yaml

This release was built on a z/OS 2.2 system.
Everything is built 64 bit and in ASCII mode.
This distribution was created on "2016-11-22-10-12" from the contents
of "/u/pdharr/Rnew/r-dist" on system RS28.

After being unpacked, this release will occupy 614488 KB.


UNPACK
The recommended way to unpack this tar.gz is:
First, cd to the directory which will contain the distribution.
Then run the command below, but if the dist.tar.gz file is in a different
directory, be sure to put that directory in front of dist.tar.gz.
/bin/cat dist.tar.gz | gunzip -c | /bin/tar xUXof -
Please note that the uppercase U and X and the lowercase o are required.

CHECK
Change your working directory to the directory where you unpacked the files,
then run these two commands:
/bin/find . -type f -filetag u -print | /bin/wc -l
/bin/find . -type f -print | /bin/wc -l
The first result is the count of untagged files,
and the second is the total number of files.
Almost all the files should be tagged.
If not, you probably forgot to use UX in the unpacking phase,
and you must follow the UNPACK instructions again.
...

python-r-develとほとんど同じ。
/usr/lpp/R332/Rに展開することにします。

[CICS004@EPLEX1:/V1R11/usr/lpp/R332/R] pwd
/RSU1206/usr/lpp/R332/R
[CICS004@EPLEX1:/V1R11/usr/lpp/R332/R] ls
r-3.3.2_b0005.161122.tar.gz
[CICS004@EPLEX1:/V1R11/usr/lpp/R332/R] gunzip r-3.3.2_b0005.161122.tar.gz
[CICS004@EPLEX1:/V1R11/usr/lpp/R332/R] ls
r-3.3.2_b0005.161122.tar
[CICS004@EPLEX1:/V1R11/usr/lpp/R332/R] tar -xUXof r-3.3.2_b0005.161122.tar
...

[CICS004@EPLEX1:/V1R11/usr/lpp/R332/R] ./bin/fix-distribution

(CHECKは省略)

READMEの記述に沿って.profile追加

.profile
# env for R332
export _BPXK_AUTOCVT=ON
export BASE=/usr/lpp/R332/R
export PATH=$BASE/bin:$PATH
export LIBPATH=$BASE/lib:$LIBPATH
export PKG_CONFIG_PATH=$BASE/lib/pkgconfig:$PKG_CONFIG_PATH
export TZDIR=$BASE/lib/R/share/zoneinfo
export RHOME=$BASE/lib/R
export R_DIST=$BASE

動作確認

hello worldスクリプト作って実行してみます。

Rコンソールでの実行

[TAG@ETP1:/home/taguchi/R] R -e 'source("hello.R")'

R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: i370-ibm-openedition (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> source("hello.R")
[1] "Hello World"
>
>

成功!

Rscriptでの実行

[TAG@ETP1:/home/taguchi/R] Rscript --verbose hello.R
running
  '/u/pdharr/Rnew/r-dist/lib/R/bin/R --slave --no-restore --file=hello.R'

Rscript execution error: EDC5129I No such file or directory. (errno2=0x0594003D)

エラーになっちゃいました!
で、Rocket社はForumで質問受け付けてくれているので、質問したら対応方法をすぐに教えてくれました。
参考:
http://forum.rocketsoftware.com/t/rscript-didnt-work/471
どうもbash前提となっていたっぽい?(詳細は不明だが、私はbash使っておらず、デフォルトのksh?だったのが影響しているらしい)
とりあえず、以下の対処でRscriptの実行もうまくいきました。

/usr/lpp/R332/python-r-devel/bin/fix-distribution を fix-shellにコピー
fix-shellを以下のように修正

fix-shell
#! /bin/sh
if [[ $0 == /* ]]; then
BIN_DIR=${0%/*}
elif [[ $0 == */* ]]; then
BIN_DIR=`pwd`/${0%/*}
else
BIN_DIR=`pwd`
fi
cd $BIN_DIR/..
#export PREFIX=`pwd`
export OLD_PREFIX=/rsusr/ported/bin/bash
export _BPXK_AUTOCVT=ON
#. $BIN_DIR/set-distribution-original-prefix
export PREFIX=/bin/sh
/bin/find . -type f -filetag t -exec $BIN_DIR/grep -q $OLD_PREFIX '{}' ';' -exec $BIN_DIR/change-path-in-file {} ';'

autotag fix-shellを実行
chmod 755 fix-shell を実行
/usr/lpp/R332/python-r-devel/で、bin/fix-shell実行

/usr/lpp/R332/R/bin/fix-distribution についても同様に修正して実行!

その後、Rscript実行したらうまくいきました!

[TAG@ETP1:/home/taguchi/R] Rscript --verbose hello.R
running
  '/usr/lpp/R332/R/lib/R/bin/R --slave --no-restore --file=hello.R'

[1] "Hello World"

Rパッケージ

追加のパッケージは、CRANのサイトからPackage Sourceをダウンロードしてインストールすることになるが、ソースからビルドすることになるのでモノによってはインストールに失敗します。(USSにはgccとか無いのでコンパイラの環境とかもちょっと違います。)

いくつかやってみたところでは、DT, shinydashboard, shinyBS, praiseは成功しました。
rJava, zoo, testthat, lubridate, tidyr はエラーとなりました。

ちなみに元々入っていたパッケージのリストはこんな感じでした。

BH
DBI
Formula
Hmisc
IRdisplay
IRkernel
KernSmooth
MASS
Matrix
R.methodsS3
R.oo
R.utils
R6
RColorBrewer
Rcpp
abind
acepack
assertthat
base
base64enc
bitops
boot
caTools
chron
class
cluster
coda
codetools
colorspace
compiler
crayon
curl
data.table
datasets
devtools
dichromat
digest
dplyr
evaluate
flexdashboard
foreign
formatR
ggplot2
gistr
git2r
grDevices
graphics
grid
gridExtra
gtable
hexbin
highr
htmltools
htmlwidgets
httpuv
httr
jsonlite
knitr
labeling
lattice
latticeExtra
lavaan
lazyeval
log4r
magrittr
maps
markdown
memoise
methods
mgcv
mime
minqa
mnormt
munsell
nlme
nnet
openssl
parallel
pbdZMQ
pbivnorm
plotrix
plyr
pryr
quadprog
rbenchmark
rbokeh
repr
reshape2
rmarkdown
rpart
rstudioapi
rzmq
scales
shiny
spatial
splines
stats
stats4
stringi
stringr
survival
tcltk
tibble
tools
translations
utils
uuid
whisker
withr
xml2
xtable
yaml

おわりに

無償でサクッと使えるけどドキュメントはあまりちゃんとしてません。Forumのレスポンスは結構早く、色々対応しようとしてくれる印象ですね。
現時点(2017年2月時点)ではPandocはz/OSにポーティングされていないようなので、R Markdownは残念ながら使えませんでした...。でもShinyは一応動かせました!

1
2
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
1
2