GNU/Linux >> Linux の 問題 >  >> Linux

Ubuntu18.04にRをインストールする方法

Rは、統計ソフトウェアの開発とデータ分析の実行に使用できるオープンソースのプログラミング言語です。 RはGNUプロジェクトであり、S言語と非常によく似ています。これは主に、データアナリスト、研究者、統計家、マーケターがデータを取得、分析、視覚化、提示するために使用します。 Rはまた、特定の研究分野向けの多くのパッケージを提供しており、さまざまな分野のアプリケーションを簡単に見つけることができます。 Rは、Linux、Windows、MacOSなどのさまざまなオペレーティングシステムで実行できます。

このチュートリアルでは、Ubuntu18.04にRプログラミング言語をインストールして使用する方法を示します。

前提条件

  • Atlantic.Netクラウドプラットフォーム上の新しいUbuntu18.04VPS。
  • サーバーで構成されているrootパスワード。

ステップ1-Atlantic.Netクラウドサーバーを作成する

まず、Atlantic.Netクラウドサーバーにログインします。少なくとも1GBのRAMを搭載したオペレーティングシステムとしてUbuntu18.04を選択して、新しいサーバーを作成します。 SSH経由でクラウドサーバーに接続し、ページの上部で強調表示されているクレデンシャルを使用してログインします。

Ubuntu 18.04サーバーにログインしたら、次のコマンドを実行して、ベースシステムを最新の利用可能なパッケージで更新します。

apt-get update -y

ステップ2–Rプログラミング言語をインストールする

まず、次のコマンドを実行して、必要なパッケージをインストールします。

apt-get install apt-transport-https software-properties-common -y

次に、次のコマンドを使用してGPGキーをダウンロードして追加します。

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

次の出力が得られるはずです:

Executing: /tmp/apt-key-gpghome.mOaFpZLCLj/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
gpg: key 51716619E084DAB9: public key "Michael Rutter <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

次に、次のコマンドを使用してCRANリポジトリを追加します。

add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'

リポジトリが追加されたら、リポジトリを更新し、次のコマンドを使用してRをインストールします。

apt-get update -y
apt-get install r-base -y

Rをインストールした後、次のコマンドでRのバージョンを確認できます。

R --version

次の出力が表示されます。

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

ステップ3–Rプログラミング言語を使用する

次のコマンドを使用して、Rコンソールをrootとして開くことができます。

sudo -i R

次の出力が得られるはずです:

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-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.

>

次に、次のコマンドを使用して、Rとともにインストールされているデフォルトのパッケージを確認します。

> getOption("defaultPackages")

次の出力が表示されます。

[1] "datasets"  "utils"     "grDevices" "graphics"  "stats"     "methods"

次のコマンドを使用して、使用可能なすべてのパッケージを一覧表示することもできます。

> (.packages(all.available=TRUE))

次の出力が得られるはずです:

 [1] "backports"  "base64url"  "filelock"   "R6"         "txtq"     
 [6] "base"       "boot"       "class"      "cluster"    "codetools"
[11] "compiler"   "datasets"   "foreign"    "graphics"   "grDevices"
[16] "grid"       "KernSmooth" "lattice"    "MASS"       "Matrix"   
[21] "methods"    "mgcv"       "nlme"       "nnet"       "parallel" 
[26] "rpart"      "spatial"    "splines"    "stats"      "stats4"   
[31] "survival"   "tcltk"      "tools"      "utils"     
>

library()コマンドを使用して、利用可能なすべてのパッケージを簡単な説明とともに一覧表示することもできます。

> library()

出力:

Packages in library ‘/usr/lib/R/library’:

base                    The R Base Package
boot                    Bootstrap Functions (Originally by Angelo Canty
                        for S)
class                   Functions for Classification
cluster                 "Finding Groups in Data": Cluster Analysis
                        Extended Rousseeuw et al.
codetools               Code Analysis Tools for R
compiler                The R Compiler Package
datasets                The R Datasets Package
foreign                 Read Data Stored by 'Minitab', 'S', 'SAS',
                       'SPSS', 'Stata', 'Systat', 'Weka', 'dBase', ...
graphics                The R Graphics Package
grDevices               The R Graphics Devices and Support for Colours
                        and Fonts
grid                    The Grid Graphics Package
KernSmooth              Functions for Kernel Smoothing Supporting Wand
                        & Jones (1995)
lattice                 Trellis Graphics for R
MASS                    Support Functions and Datasets for Venables and
                        Ripley's MASS
Matrix                  Sparse and Dense Matrix Classes and Methods
methods                 Formal Methods and Classes
mgcv                    Mixed GAM Computation Vehicle with Automatic
                        Smoothness Estimation
nlme                    Linear and Nonlinear Mixed Effects Models
nnet                    Feed-Forward Neural Networks and Multinomial

次のコマンドを使用して、Rコンソールを終了できます。

> quit()

ステップ4–コンソールからRパッケージをインストールする

Rコンソール内にRパッケージをインストールすることもできます。まず、次のコマンドを使用して、ルートとしてRコンソールにログインします。

sudo -i R

次に、次のコマンドを使用してtxtqパッケージをインストールします。

> install.packages("txtq")

次の出力が得られるはずです:

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/txtq_0.2.0.tar.gz'
Content type 'application/x-gzip' length 10536 bytes (10 KB)
==================================================
downloaded 10 KB

* installing *source* package ‘txtq’ ...
** package ‘txtq’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (txtq)

The downloaded source packages are in
            ‘/tmp/RtmpHfzZs1/downloaded_packages’
>

次のコマンドを使用して、インストールされているパッケージを削除することもできます。

> remove.packages("txtq")

ステップ5–LinuxCLIからRパッケージをインストールする

コマンドラインインターフェイスを使用してRパッケージをインストールすることもできます。

:まだR CLIを使用している場合は、 CTRL Dを押します。 いいえを選択します ワークスペースを保存するように求められたら。

まず、次のコマンドを使用して、CRANWebサイトからtxtqパッケージをダウンロードします。

wget -q https://cran.r-project.org/src/contrib/txtq_0.2.0.tar.gz

ダウンロードしたら、次のコマンドでインストールできます:

sudo R CMD INSTALL txtq_0.2.0.tar.gz

インストールすると、次の出力が表示されます。

* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘txtq’ ...
** package ‘txtq’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (txtq)

結論

今のところ以上です。これで、Ubuntu18.04サーバーにRをインストールして使用する方法を十分に理解できたと思います。これを使用して、Atlantic.NetのVPSでRプログラミング言語を使用して統計ソフトウェアを構築できます。


Linux
  1. Ubuntu18.04にLogstashをインストールする方法

  2. Ubuntu20.04にXWikiをインストールする方法

  3. Ubuntu20.04にphpBBをインストールする方法

  1. Ubuntu20.04にRをインストールする方法

  2. Ubuntu18.04にGoをインストールする方法

  3. Ubuntu20.04にMongoDBをインストールする方法

  1. Ubuntu18.04にRをインストールする方法

  2. Ubuntu20.04にSyncthingをインストールする方法

  3. Ubuntu20.04にUserminをインストールする方法