(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【RHEL/R言語】yumでR言語をインストールする

スポンサーリンク

目的

RHEL7でR言語を利用できる環境を用意する。

環境

Google Cloud Platform環境のVMインスタンス

$ cat /etc/os-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.6 (Maipo)"
$ arch
x86_64

手順

R言語をインストール

yumコマンドでインストールをおこないます。
まずはyum infoで情報を確認します。

# yum info R
Available Packages
Name        : R
Arch        : x86_64
Version     : 3.5.2
Release     : 2.el7
Size        : 30 k
Repo        : epel/x86_64
Summary     : A language for data analysis and graphics
URL         : http://www.r-project.org
License     : GPLv2+
Description : This is a metapackage that provides both core R userspace and
            : all R development components.
            :
            : R is a language and environment for statistical computing and
            : graphics. R is similar to the award-winning S system, which was
            : developed at Bell Laboratories by John Chambers et al. It provides
            : a wide variety of statistical and graphical techniques (linear and
            : nonlinear modelling, statistical tests, time series analysis,
            : classification, clustering, ...).
            :
            : R is designed as a true computer language with control-flow
            : constructions for iteration and alternation, and it allows users
            : to add additional functionality by defining new functions. For
            : computationally intensive tasks, C, C++ and Fortran code can be
            : linked and called at run time.

リポジトリに存在が確認できたのでインストールを行います。

# yum -y install R
Resolving Dependencies
--> Running transaction check
...
Installed:
  R.x86_64 0:3.5.2-2.el7
...
Complete!

インストール後はwhichコマンドでRのパスを確認します。

# which R
/usr/bin/R
Rの起動確認
# R

で起動

q()

で終了できます。

以下のように起動終了画面が出ます。

# R

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (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.

  Natural language support but running in an English locale

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.

> quit()
Save workspace image? [y/n/c]: n

必要なパッケージはinstall.packagesで行えます。
初めて実施すると以下のようにミラーサイトを指定します。
今回は日本のミラーサイトを選びました。

> install.packages("openssl")
Installing package into ‘/usr/lib64/R/library(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors

 1: 0-Cloud [https]                   2: Algeria [https]
 3: Australia (Canberra) [https]      4: Australia (Melbourne 1) [https]
 5: Australia (Melbourne 2) [https]   6: Australia (Perth) [https]
 7: Austria [https]                   8: Belgium (Ghent) [https]
 9: Brazil (PR) [https]              10: Brazil (RJ) [https]
11: Brazil (SP 1) [https]            12: Brazil (SP 2) [https]
13: Bulgaria [https]                 14: Chile 1 [https]
15: Chile 2 [https]                  16: China (Hong Kong) [https]
17: China (Guangzhou) [https]        18: China (Lanzhou) [https]
19: China (Shanghai 1) [https]       20: China (Shanghai 2) [https]
21: Colombia (Cali) [https]          22: Czech Republic [https]
23: Denmark [https]                  24: East Asia [https]
25: Ecuador (Cuenca) [https]         26: Ecuador (Quito) [https]
27: Estonia [https]                  28: France (Lyon 1) [https]
29: France (Lyon 2) [https]          30: France (Marseille) [https]
31: France (Montpellier) [https]     32: France (Paris 2) [https]
33: Germany (Erlangen) [https]       34: Germany (Göttingen) [https]
35: Germany (Münster) [https]        36: Greece [https]
37: Iceland [https]                  38: Indonesia (Jakarta) [https]
39: Ireland [https]                  40: Italy (Padua) [https]
41: Japan (Tokyo) [https]            42: Japan (Yonezawa) [https]
43: Korea (Busan) [https]            44: Korea (Gyeongsan-si) [https]
45: Korea (Seoul 1) [https]          46: Korea (Ulsan) [https]
47: Malaysia [https]                 48: Mexico (Mexico City) [https]
49: Norway [https]                   50: Philippines [https]
51: Serbia [https]                   52: Spain (A Coruña) [https]
53: Spain (Madrid) [https]           54: Sweden [https]
55: Switzerland [https]              56: Turkey (Denizli) [https]
57: Turkey (Mersin) [https]          58: UK (Bristol) [https]
59: UK (London 1) [https]            60: USA (CA 1) [https]
61: USA (IA) [https]                 62: USA (KS) [https]
63: USA (MI 1) [https]               64: USA (OR) [https]
65: USA (TN) [https]                 66: USA (TX 1) [https]
67: Uruguay [https]                  68: (other mirrors)

Selection: 42
HelloWorld

R言語はスクリプト言語なので、Rが起動した状態で以下のようにコマンド押下すればHelloWorldを表示できます。

> print("Helloworld")
[1] "Helloworld"

またviなどで以下のようなファイルを.r形式で用意して

# cat hello.r
print("Helloworld")

R言語起動後にsource関数で起動

> source("hello.r")
[1] "Helloworld"

またはコマンドラインから直接起動も可能です。

#  R --vanilla --slave < hello.r
[1] "Helloworld"

以上、Linux環境にR言語をインストールした際の備忘録でした。