GNU/Linux >> Tutoriales Linux >  >> Linux

Cómo instalar R en Ubuntu 18.04

R es un lenguaje de programación de código abierto que se puede utilizar para desarrollar software estadístico y realizar análisis de datos. R es un proyecto GNU y muy similar al lenguaje S. Es utilizado principalmente por analistas de datos, investigadores, estadísticos y especialistas en marketing para recuperar, analizar, visualizar y presentar los datos. R también ofrece muchos paquetes para áreas específicas de estudio, lo que facilita encontrar aplicaciones en diferentes campos. R se puede ejecutar en varios sistemas operativos, incluidos Linux, Windows y MacOS.

En este tutorial, le mostraremos cómo instalar y usar el lenguaje de programación R en Ubuntu 18.04.

Requisitos

  • Un Ubuntu 18.04 VPS nuevo en Atlantic.Net Cloud Platform.
  • Una contraseña raíz configurada en su servidor.

Paso 1:crear el servidor en la nube de Atlantic.Net

Primero, inicie sesión en su servidor en la nube de Atlantic.Net. Cree un nuevo servidor, eligiendo Ubuntu 18.04 como sistema operativo con al menos 1 GB de RAM. Conéctese a su servidor en la nube a través de SSH e inicie sesión con las credenciales resaltadas en la parte superior de la página.

Una vez que haya iniciado sesión en su servidor Ubuntu 18.04, ejecute el siguiente comando para actualizar su sistema base con los últimos paquetes disponibles.

apt-get update -y

Paso 2:instalar el lenguaje de programación R

Primero, instale los paquetes necesarios ejecutando el siguiente comando:

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

A continuación, descargue y agregue la clave GPG con el siguiente comando:

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

Deberías obtener el siguiente resultado:

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

A continuación, agregue el repositorio CRAN con el siguiente comando:

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

Una vez que se haya agregado el repositorio, actualice el repositorio e instale R con el siguiente comando:

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

Después de instalar R, puede verificar la versión de R con el siguiente comando:

R --version

Debería ver el siguiente resultado:

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/.

Paso 3:utilice el lenguaje de programación R

Puede abrir la consola R como root con el siguiente comando:

sudo -i R

Deberías obtener el siguiente resultado:

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.

>

A continuación, verifique los paquetes predeterminados instalados con R usando el siguiente comando:

> getOption("defaultPackages")

Debería ver el siguiente resultado:

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

También puede enumerar todos los paquetes disponibles con el siguiente comando:

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

Deberías obtener el siguiente resultado:

 [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"     
>

También puede usar el comando library() para enumerar todos los paquetes disponibles con una breve descripción:

> library()

Salida:

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

Puede salir de la consola R con el siguiente comando:

> quit()

Paso 4:instalar paquetes R desde la consola

También puede instalar paquetes de R dentro de la consola de R. Primero, inicie sesión en la consola R como root con el siguiente comando:

sudo -i R

Luego, instale el paquete txtq usando el siguiente comando:

> install.packages("txtq")

Deberías obtener el siguiente resultado:

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

También puede eliminar el paquete instalado con el siguiente comando:

> remove.packages("txtq")

Paso 5:instalar paquetes R desde la CLI de Linux

También puede instalar los paquetes R mediante la interfaz de línea de comandos.

NOTA :si todavía está en R CLI, presione CTRL D y seleccione no cuando se le solicite guardar el espacio de trabajo.

Primero, descargue el paquete txtq del sitio web de CRAN con el siguiente comando:

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

Una vez descargado, puedes instalarlo con el siguiente comando:

sudo R CMD INSTALL txtq_0.2.0.tar.gz

Una vez instalado, debería ver el siguiente resultado:

* 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)

Conclusión

Eso es todo por ahora. Espero que ahora comprenda lo suficiente sobre cómo instalar y usar R en el servidor Ubuntu 18.04. Ahora puede usarlo para construir un software estadístico usando el lenguaje de programación R en su VPS desde Atlantic.Net.


Linux
  1. Cómo instalar R en Ubuntu 20.04

  2. Cómo instalar Logstash en Ubuntu 18.04

  3. Cómo instalar XWiki en Ubuntu 20.04

  4. Cómo instalar phpBB en Ubuntu 20.04

  5. Cómo instalar MongoDB en Ubuntu 20.04

Cómo instalar Ruby en Ubuntu 18.04

Cómo instalar Kanboard en Ubuntu 20.04

Cómo instalar OpenMAINT en Ubuntu 20.04

Cómo instalar Socioboard en Ubuntu 20.04

Cómo instalar PrestaShop en Ubuntu 20.04

Cómo instalar MediaWiki en Ubuntu 20.04