Difference between revisions of "R"

From ArchWiki
Jump to: navigation, search
(Added a note about a quirk with RStudio configuration.)
(update Pkg/AUR templates)
(Tag: wiki-scripts)
 
(124 intermediate revisions by 28 users not shown)
Line 1: Line 1:
[[Category:Programming language]]
+
[[Category:Mathematics and science]]
{{stub}}
+
[[Category:Programming languages]]
 +
[[ja:R]]
 +
{{Related articles start}}
 +
{{Related|Intel C++}}
 +
{{Related articles end}}
 +
[http://www.r-project.org/ R] is a "free software environment for statistical computing and graphics (http://www.r-project.org/)."
  
''R is a free software environment for statistical computing and graphics''  (http://www.r-project.org/).
+
== Installation ==
 +
=== Basic package ===
  
== Installing R ==
+
[[Install]] the {{Pkg|r}} package. The installation of external packages within the R environment may require {{pkg|gcc-fortran}}.
  
It is very easy to install R in Arch Linux:
+
=== Initial configuration ===
# pacman -S r
+
  
R has some dependencies in tcl and tk (required to install an R package from R). To install then:
+
Please refer to [http://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html Initialization at Start of an R Session] to get a detailed understanding of startup process.
# pacman -S tcl tk
+
The home directory of the {{ic|R}} installation is {{ic|/usr/lib/R}}. Base packages are found in {{ic|/usr/lib/R/library/base}} and '''site''' configuration files in {{ic|/etc/R/}}. Aspects of the [[Locale]] are accessed by the functions {{ic|Sys.getlocale}} and {{ic|Sys.localeconv}} within the {{ic|R}} session. Locales will be the one defined in your system.
  
Some external packages may require to be compile in Fortran as well, so installing gcc-fortran can be a good idea:
+
To start a {{ic|R}} session, open your terminal and type this command:
  # pacman -S gcc-fortran
+
$ R
 +
{{Note|
 +
* Use {{ic|Shift+u}} for the command (some shells use the {{ic|r}} letter to repeat the last entered command). Once in your {{ic|R}} session, the prompt will change to {{ic|>}}
 +
* '''site''' refers to '''system-wide''' in R Documentation}}
 +
Run {{ic|?Startup}} to read the documentation about system file configuration, {{ic|help()}} for the on-line help,{{ic|help.start()}} for the HTML browser interface to help, {{ic|demo()}} for some demos and {{ic|q()}} to close the session and quit.
  
=== Installing R packages ===
+
When closing the session, you will be prompted : {{ic|Save workspace Image ?[y/n/c]}}. The ''workspace'' is your current working environment and include any user-defined objects, functions. The saved image is stored in {{ic|.RData}} format and will be automatically reloaded the next time {{ic|R}} is started. You can manually save the workspace at any time in the session with the {{ic|save.image(image.RData)}} command, save as many images as you want (eg : ''image1.RData'', ''image2.RData''). You can load image with the {{ic|load.image(image.RData)}} command at any time of your session.
There are many add-on R packages, which can be browsed on [http://cran.r-project.org/ The R Website.]. They can be installed from within R using the R install.packages command. It is not necessary to be superuser or have root privileges when doing this -- R can install its packages locally for the individual user. This is the safest way to install R packages and won't conflict with the pacman package management.
+
  
To set the location of your local R package library, create a {{ic|~/.Renviron}} file and set R_LIBS_USER:
+
{{Tip|
 +
* Tired of R's verbose startup message ? Then start {{ic|R}} with the {{ic|--quiet}} command-line option.
 +
{{ic|$ R --quiet}}
 +
You can {{ic|alias R ="R --quiet"}} in one of your [[Startup files]]
 +
* Unless explicitly defined somewhere in your configuration files, {{ic|R}} will start in your $HOME directory. If you want to start in a specific directory. first time you create the directory do this:
 +
$ R
 +
> setwd("path/to/your/directory")
 +
> q()
 +
Save workspace image? [y/n/c]: y
 +
{{ic|R}} will create a '''.RData''' image file of your current environment. Then, when double-clicking this file, {{ic|R}} will automatically change its working directory to the file's directory.
 +
* colorize console output:
 +
> download.file("http://www.lepem.ufc.br/jaa/vimr/colorout_1.1-1.tar.gz", destfile = "colorout_1.1-1.tar.gz")
 +
> install.packages("colorout_1.1-1.tar.gz", type = "source", repos = NULL)
 +
}}
  
{{hc|~/.Renviron|
+
===Variables===
R_LIBS_USER=/home/username/path/to/R/packages}}
+
{{ic|R}} can be confusing when it comes to [[environment variables]], as they are large and duplicated following the '''site''' or '''user''' sides. There are two sorts of files used in startup: ''environment files'', defined by {{ic|$R_ENVIRON}} and ''profile files'', defined by {{ic|$R_PROFILE}}.
  
== Running R ==
+
Most important variables can be found on [http://stat.ethz.ch/R-manual/R-devel/library/base/html/EnvVar.html Environment Variables R Documentation].
R can be run from the command line, by using the R command:
+
 
  $ R
+
====R_ENVIRON====
 +
At startup, {{ic|R}} search at early stage for '''site''' and '''user''' {{ic|.Renviron}} files to process for setting [[environment variables]]. The '''site''' file is located in {{ic|/etc/R}}, and generated by configure.
 +
 
 +
The name of the user file can be specified by the {{ic|R_ENVIRON_USER}} environment variable. 
 +
If you do not specify any file, {{ic|R}} will automatically read {{ic|.Renviron}} in your home directory if there is one. In case you want to use another emplacement for this file, append this line {{ic| export R_ENVIRON_USER ="path/to/.Renviron"}} in one of your [[startup files]]. This is the place to set all kind of environment variables using the '''R syntax'''.
 +
 
 +
====R_PROFILE====
 +
Then {{ic|R}} searches for the '''site-wilde''' {{ic|Rprofile.site}} defined by the {{ic|R_PROFILE}} environment variable. This file does not exist after a fresh installation.
 +
Finally, {{ic|R}} seraches for '''user''' {{ic|R_PROFILE_USER}}. if unset, a file called {{ic|.Rprofile}} is searched for in the current directory, returned by the {{ic|R}} command {{ic|> getwd()}} or in the user's home directory. This is the place to put all your custom {{ic|R}} code.
 +
 
 +
== Installing R packages ==
 +
There are many add-on {{ic|R}} packages, which can be browsed on [http://cran.r-project.org/web/packages/available_packages_by_date.html The R Website.]. They can be installed from within {{ic|R}} using the {{ic|'''install.packages(c("pkgname"))'''}} command. {{ic|R}} can install its packages locally as '''per user''' local settings or '''system wide'''.
 +
 +
Within your {{ic|R }} session, run this command to check that your user library exists and is set correctly:
 +
{{hc|> Sys.getenv("R_LIBS_USER")|
 +
[1] "/path/to/directory/R/packages"}}
 +
Installation within your {{ic|R}} session is the safest way and will not conflict with the [[pacman]] package management, but there is another method to install packages. Run the following command in your terminal:
 +
 
 +
{{bc|$ R CMD INSTALL -l $R_LIBS_USER ''pkg1 pkg2 ...''}}
 +
 
 +
=== Upgrading R packages ===
 +
==== Within a R session ====
 +
  > update.packages(ask=FALSE)
 +
Or when you also need to rebuild packages which were built for an older version:
 +
> update.packages(ask=FALSE,checkBuilt=TRUE)
 +
{{Tip|upgrading packages from your '''R''' session can quickly be a pain if you have too many loaded packages at start up. For packages to be upgraded, they need to be ''not loaded''. Best practice is to start a new clean R session this way: {{ic| R --vanilla}} then run the upgrade.
 +
}}
 +
==== Within a shell ====
 +
First, [[Install]] {{AUR|littler}} from the [[Arch User Repository]]. This package allows direct execution of '''R''' commands and can be seen as a scripting front-end. Then, visit [http://dirk.eddelbuettel.com/code/littler.examples.html dirk.eddelbuettel] webiste about '''littler'''. Below is the script to run packages updates:
 +
{{bc|
 +
#!/usr/bin/env r
 +
#
 +
# a simple example to update packages in /usr/local/lib/R/site-library
 +
# parameters are easily adjustable
 +
 
 +
repos <- "http://cran.rstudio.com"
 +
 
 +
lib.loc <- Sys.getenv("R_LIBS_USER")
 +
 
 +
update.packages(repos&#61;repos, ask&#61;FALSE, lib.loc&#61;lib.loc)
 +
}}
 +
 
 +
Put this script in your favorite place and make it executable. Of course, feel free to modify the repo URL and the library location.
 +
 
 +
{{Warning|when using [[zsh]], '''r''' is a builtin command. You will have to either use an explicit path {{ic|/usr/bin/r}} or create an alias under a different name.}}
 +
 
 +
==== Automatically after R upgrades ====
 +
R packages may not be compatible between R versions. You may want to automatically upgrade them and rebuild them if necessary when R upgrades. This can be accomplished with a pacman hook:
 +
 
 +
{{hc|/etc/pacman.d/hooks/r-upgrade.hook|<nowiki>
 +
[Trigger]
 +
Operation = Upgrade
 +
Type = Package
 +
Target = r
 +
 
 +
[Action]
 +
Description = Updates R packages and rebuilds them if necessary after R upgrade
 +
# Depends is optional if this should depend on another package
 +
Depends =
 +
When = PostTransaction
 +
Exec = Rscript -e 'update.packages(checkBuilt = TRUE, ask = FALSE)'
 +
</nowiki>}}
 +
 
 +
==Configuration files==
 +
 
 +
The two user configuration files you want in your home folder are {{ic|.Renviron}} and {{ic|Rprofile.r}}. If you want to keep your {{ic|$HOME}} directory as clean as possible, a good practice will be to make the {{ic|~/.config/r}} directory, put the {{ic|Rprofile.r}} file at the root of the directory and append all your {{ic|R}} code  in this file.
 +
===.Renviron===
 +
Lines in {{ic|Renviron}} file should be either comment lines starting with '''#''' or lines of the form ''name&#61;value''.Here is a very basic {{ic|.Renviron}} you can start with:
 +
{{hc|.Renviron|                                     
 +
R_HOME_USER &#61; /path/to/your/r/directory
 +
R_PROFILE_USER &#61; ${HOME}/.config/r/Rprofile.r
 +
R_LIBS_USER &#61; /path/to/your/r/library
 +
R_HISTFILE &#61; /path/to/your/filename.Rhistory                                            # Do not forget to append the '''.Rhistory'''
 +
R_DEFAULT_PACKAGES &#61; 'datasets,utils,grDevices,graphics,stats,methods,rJava,colorout'    # load some default packages at start up
 +
MYSQL_HOME &#61; /var/lib/mysql                 
 +
}}
 +
 
 +
===Rprofile.r===
 +
For convenient reasons, you can put a specific {{ic|Rprofile.r}} in each of your usual working directories. One facility would be to dedicate one directory per project, with its specific profile. When {{ic|R}} will change to the working directory, it will then read the {{ic|Rprofile.r}} file inside it.
 +
 
 +
Here is a very short list of useful options and code:
 +
{{hc|Rprofile.r|
 +
setwd("path/to/startup/directory")                                                                  # define a start up working directory
 +
.First <- function(){
 +
#welcome message
 +
message("Welcome back ", Sys.getenv("USER"),"!\n","working directory is:", getwd())
 +
}                                                     
 +
options(prompt &#61; paste(paste (Sys.info () [c ("user", "nodename")], collapse &#61; "@"),"[R] "))        # customize your R prompt with username and hostname in this format: '''user@hostname [R]'''
 +
options(digits &#61; 12)                                                                                # number of digits to print. Default is 7, max is 15
 +
options(stringsAsFactors &#61; FALSE)
 +
options(show.signif.stars &#61; FALSE)
 +
error &#61; quote(dump.frames("${R_HOME_USER}/testdump", TRUE))                                          # post-mortem debugiging facilities
 +
}}
 +
You can add more [http://stat.ethz.ch/R-manual/R-devel/library/base/html/options.html global options] to customize your {{ic|R}} environment.
 +
See this [http://stackoverflow.com/questions/1189759/expert-r-users-whats-in-your-rprofile post] for more user configurations.
  
 
== Adding a graphical frontend to R ==
 
== Adding a graphical frontend to R ==
  
The linux version of R does not include a graphical user interface. However, third-party user interfaces for R are available, such as R commander and RKWard.  
+
R does not include a point-and-click graphical user interface for statistics or data manipulation. However, third-party user interfaces for R are available, such as R commander and RKWard.
  
 
=== R Commander frontend ===
 
=== R Commander frontend ===
R Commander is a popular user interface to R. There is no Arch linux package available to install R commander, but it is an R package so it can be installed easily from within R.  R Commander requires Tk:
+
R Commander is a popular user interface to R. There is no Arch linux package available to install R commander, but it is an R package so it can be installed easily from within R.  R Commander requires {{Pkg|tk}} to be [[installed]].
# pacman -S tk
+
  
 
To install R Commander, run 'R' from the command line. Then type:
 
To install R Commander, run 'R' from the command line. Then type:
Line 45: Line 159:
  
 
=== RKWard frontend ===
 
=== RKWard frontend ===
RKWard is an open-source frontend which allows for data import and browsing as well as running common statistical tests and plots. You can install {{AUR|rkward}} from [[Arch User Repository|AUR]].
+
RKWard is an open-source frontend which allows for data import and browsing as well as running common statistical tests and plots. You can install {{AUR|rkward}} from [[AUR]].
 +
 
 +
== Editors IDEs and notebooks with R support ==
  
 
=== Rstudio IDE ===
 
=== Rstudio IDE ===
 
RStudio an open-source R IDE. It includes many modern conveniences such as parentheses matching, tab-completion, tool-tip help popups, and a spreadsheet-like data viewer.
 
RStudio an open-source R IDE. It includes many modern conveniences such as parentheses matching, tab-completion, tool-tip help popups, and a spreadsheet-like data viewer.
  
Install {{AUR|rstudio-desktop-bin}} (binary version from the Rstudio project website) or {{AUR|rstudio-desktop-git}} (development version) from [[Arch User Repository|AUR]].
+
Install {{AUR|rstudio-desktop-bin}} (binary version from the Rstudio project website) or {{AUR|rstudio-desktop-git}} (development version) from [[AUR]].
  
 
The R library path is often configured with the R_LIBS environment variable. RStudio ignores this, so the user must set R_LIBS_USER in {{ic|~/.Renviron}}, as documented above.
 
The R library path is often configured with the R_LIBS environment variable. RStudio ignores this, so the user must set R_LIBS_USER in {{ic|~/.Renviron}}, as documented above.
 +
 +
=== Rstudio server ===
 +
 +
RStudio Server enables you to provide a browser based interface to a version of R running on a remote Linux server.
 +
 +
Install {{AUR|rstudio-server-git}}. The two main configuration files are {{ic|/etc/rstudio/rserver.conf}} and {{ic|/etc/rstudio/rsession.conf}}. They are not created during the install, so you will need to ''create'' and ''edit'' them. For information about configure options, please refer to [https://support.rstudio.com/hc/en-us/articles/200552306-Getting-Started rstudio getting started] documentation.
 +
 +
To start the server, please [[Systemd#Using_units|enable and start]] the  {{ic|rstudio-server.service}} unit file provided with the package.
 +
 +
=== Emacs Speaks Statistics ===
 +
{{Pkg|emacs}} users can interact with R via the {{AUR|emacs-ess}} package.
 +
 +
=== Nvim-R ===
 +
The {{AUR|nvim-r}} package allows {{Pkg|vim}} and {{Pkg|neovim}} users to code in R, including editing and rendering of R markdown (Rmd) files, execution of R code in a separate pane, inspection of variables, and integrated help panes.
 +
 +
=== Cantor ===
 +
{{Pkg|cantor}} is a notebook application developed by KDE that includes support for R.
 +
 +
=== Jupyter notebook ===
 +
{{Pkg|jupyter-notebook}} is a browser based notebook with support for many programming languages. R support can be added by installing the [https://github.com/IRkernel/IRkernel IRkernel].
 +
 +
== Optimized packages ==
 +
The numerical libraries that comes with the R (generic {{Pkg|blas}}, LAPACK) do not have multithreading capabilities. Replacing the reference {{Pkg|blas}} package with an optimized BLAS can produce dramatic speed increases for many common computations in R. However the available optimized BLAS packages all have drawbacks such as requiring a commercial license or [http://blog.revolutionanalytics.com/2015/10/edge-cases-in-using-the-intel-mkl-and-parallel-programming.html potentially interfering with the standard R functionality for parallel processing]. If you really need faster linear algebra in R you may consider the following options.
 +
 +
=== OpenBLAS ===
 +
{{AUR|openblas}} can be installed from the [[AUR]], replacing the reference {{Pkg|blas}} from extra. If you are using the regular {{Pkg|r}} package from extra no further configuration is needed; R is configured to use the system BLAS and will use OpenBLAS once it is installed.
 +
=== Intel MKL ===
 +
'''If your processors are Intel''', it is strongly advised to use the [http://software.intel.com/en-us/intel-mkl Intel math Kernel Library]. The '''MKL''', beyond the capabilities of multithreading, also has specific optimizations for Intel processors, with performance far superior to traditional libraries.
 +
 +
Please first [[Install]] the {{AUR|intel-mkl}} package available from [[AUR]], then the {{AUR|r-mkl}} package.
 +
 +
{{Note|
 +
* if you install the {{AUR|r-mkl}} with '''R''' already installed, you will be prompted to remove '''R'''. Once '''r-mkl''' is installed, please run on '''R''' console the following command :
 +
{{ic|> update.packages(checkBuilt&#61;TRUE)}}
 +
* here are elapsed time in sec from computing 15 tests with default GCC build and icc/MKL build: ''274.93 sec'' for GCC build, ''21.01 sec'' for icc/MKL build. See [https://stat.ethz.ch/pipermail/r-help/2014-September/421574.html this post] for more information.
 +
}}
 +
 +
=== intel-advisor-xe ===
 +
[http://software.intel.com/en-us/intel-advisor-xe intel-advisor] delivers top application performance with C, C++ and Fortran compilers, libraries and analysis tools.
 +
 +
Install the {{AUR|intel-advisor-xe}}{{Broken package link|package not found}} package.
 +
 +
== See also ==
 +
* [http://www.rseek.org/ RSeek] A search engine for R related material.

Latest revision as of 15:02, 11 September 2016

Related articles

R is a "free software environment for statistical computing and graphics (http://www.r-project.org/)."

Installation

Basic package

Install the r package. The installation of external packages within the R environment may require gcc-fortran.

Initial configuration

Please refer to Initialization at Start of an R Session to get a detailed understanding of startup process. The home directory of the R installation is /usr/lib/R. Base packages are found in /usr/lib/R/library/base and site configuration files in /etc/R/. Aspects of the Locale are accessed by the functions Sys.getlocale and Sys.localeconv within the R session. Locales will be the one defined in your system.

To start a R session, open your terminal and type this command:

$ R
Note:
  • Use Shift+u for the command (some shells use the r letter to repeat the last entered command). Once in your R session, the prompt will change to >
  • site refers to system-wide in R Documentation

Run ?Startup to read the documentation about system file configuration, help() for the on-line help,help.start() for the HTML browser interface to help, demo() for some demos and q() to close the session and quit.

When closing the session, you will be prompted : Save workspace Image ?[y/n/c]. The workspace is your current working environment and include any user-defined objects, functions. The saved image is stored in .RData format and will be automatically reloaded the next time R is started. You can manually save the workspace at any time in the session with the save.image(image.RData) command, save as many images as you want (eg : image1.RData, image2.RData). You can load image with the load.image(image.RData) command at any time of your session.

Tip:
  • Tired of R's verbose startup message ? Then start R with the --quiet command-line option.

$ R --quiet You can alias R ="R --quiet" in one of your Startup files

  • Unless explicitly defined somewhere in your configuration files, R will start in your $HOME directory. If you want to start in a specific directory. first time you create the directory do this:
$ R
> setwd("path/to/your/directory")
> q()
Save workspace image? [y/n/c]: y

R will create a .RData image file of your current environment. Then, when double-clicking this file, R will automatically change its working directory to the file's directory.

  • colorize console output:
> download.file("http://www.lepem.ufc.br/jaa/vimr/colorout_1.1-1.tar.gz", destfile = "colorout_1.1-1.tar.gz")
> install.packages("colorout_1.1-1.tar.gz", type = "source", repos = NULL)

Variables

R can be confusing when it comes to environment variables, as they are large and duplicated following the site or user sides. There are two sorts of files used in startup: environment files, defined by $R_ENVIRON and profile files, defined by $R_PROFILE.

Most important variables can be found on Environment Variables R Documentation.

R_ENVIRON

At startup, R search at early stage for site and user .Renviron files to process for setting environment variables. The site file is located in /etc/R, and generated by configure.

The name of the user file can be specified by the R_ENVIRON_USER environment variable. If you do not specify any file, R will automatically read .Renviron in your home directory if there is one. In case you want to use another emplacement for this file, append this line export R_ENVIRON_USER ="path/to/.Renviron" in one of your startup files. This is the place to set all kind of environment variables using the R syntax.

R_PROFILE

Then R searches for the site-wilde Rprofile.site defined by the R_PROFILE environment variable. This file does not exist after a fresh installation. Finally, R seraches for user R_PROFILE_USER. if unset, a file called .Rprofile is searched for in the current directory, returned by the R command > getwd() or in the user's home directory. This is the place to put all your custom R code.

Installing R packages

There are many add-on R packages, which can be browsed on The R Website.. They can be installed from within R using the install.packages(c("pkgname")) command. R can install its packages locally as per user local settings or system wide.

Within your R session, run this command to check that your user library exists and is set correctly:

> Sys.getenv("R_LIBS_USER")
[1] "/path/to/directory/R/packages"

Installation within your R session is the safest way and will not conflict with the pacman package management, but there is another method to install packages. Run the following command in your terminal:

$ R CMD INSTALL -l $R_LIBS_USER pkg1 pkg2 ...

Upgrading R packages

Within a R session

> update.packages(ask=FALSE)

Or when you also need to rebuild packages which were built for an older version:

> update.packages(ask=FALSE,checkBuilt=TRUE)
Tip: upgrading packages from your R session can quickly be a pain if you have too many loaded packages at start up. For packages to be upgraded, they need to be not loaded. Best practice is to start a new clean R session this way: R --vanilla then run the upgrade.

Within a shell

First, Install littlerAUR from the Arch User Repository. This package allows direct execution of R commands and can be seen as a scripting front-end. Then, visit dirk.eddelbuettel webiste about littler. Below is the script to run packages updates:

#!/usr/bin/env r 
#
# a simple example to update packages in /usr/local/lib/R/site-library
# parameters are easily adjustable

repos <- "http://cran.rstudio.com"

lib.loc <- Sys.getenv("R_LIBS_USER")

update.packages(repos=repos, ask=FALSE, lib.loc=lib.loc)

Put this script in your favorite place and make it executable. Of course, feel free to modify the repo URL and the library location.

Warning: when using zsh, r is a builtin command. You will have to either use an explicit path /usr/bin/r or create an alias under a different name.

Automatically after R upgrades

R packages may not be compatible between R versions. You may want to automatically upgrade them and rebuild them if necessary when R upgrades. This can be accomplished with a pacman hook:

/etc/pacman.d/hooks/r-upgrade.hook
[Trigger]
Operation = Upgrade
Type = Package
Target = r

[Action]
Description = Updates R packages and rebuilds them if necessary after R upgrade
# Depends is optional if this should depend on another package
Depends = 
When = PostTransaction
Exec = Rscript -e 'update.packages(checkBuilt = TRUE, ask = FALSE)'

Configuration files

The two user configuration files you want in your home folder are .Renviron and Rprofile.r. If you want to keep your $HOME directory as clean as possible, a good practice will be to make the ~/.config/r directory, put the Rprofile.r file at the root of the directory and append all your R code in this file.

.Renviron

Lines in Renviron file should be either comment lines starting with # or lines of the form name=value.Here is a very basic .Renviron you can start with:

.Renviron
                                       
R_HOME_USER = /path/to/your/r/directory
R_PROFILE_USER = ${HOME}/.config/r/Rprofile.r
R_LIBS_USER = /path/to/your/r/library
R_HISTFILE = /path/to/your/filename.Rhistory                                             # Do not forget to append the .Rhistory
R_DEFAULT_PACKAGES = 'datasets,utils,grDevices,graphics,stats,methods,rJava,colorout'    # load some default packages at start up
MYSQL_HOME = /var/lib/mysql                  

Rprofile.r

For convenient reasons, you can put a specific Rprofile.r in each of your usual working directories. One facility would be to dedicate one directory per project, with its specific profile. When R will change to the working directory, it will then read the Rprofile.r file inside it.

Here is a very short list of useful options and code:

Rprofile.r
setwd("path/to/startup/directory")                                                                   # define a start up working directory
.First <- function(){
#welcome message
message("Welcome back ", Sys.getenv("USER"),"!\n","working directory is:", getwd())
}                                                       
options(prompt = paste(paste (Sys.info () [c ("user", "nodename")], collapse = "@"),"[R] "))         # customize your R prompt with username and hostname in this format: user@hostname [R]
options(digits = 12)                                                                                 # number of digits to print. Default is 7, max is 15
options(stringsAsFactors = FALSE)
options(show.signif.stars = FALSE)
error = quote(dump.frames("${R_HOME_USER}/testdump", TRUE))                                          # post-mortem debugiging facilities

You can add more global options to customize your R environment. See this post for more user configurations.

Adding a graphical frontend to R

R does not include a point-and-click graphical user interface for statistics or data manipulation. However, third-party user interfaces for R are available, such as R commander and RKWard.

R Commander frontend

R Commander is a popular user interface to R. There is no Arch linux package available to install R commander, but it is an R package so it can be installed easily from within R. R Commander requires tk to be installed.

To install R Commander, run 'R' from the command line. Then type:

> install.packages("Rcmdr", dependencies=TRUE)

This can take some time.

You can then start R Commander from within R using the library command:

> library("Rcmdr")

RKWard frontend

RKWard is an open-source frontend which allows for data import and browsing as well as running common statistical tests and plots. You can install rkwardAUR from AUR.

Editors IDEs and notebooks with R support

Rstudio IDE

RStudio an open-source R IDE. It includes many modern conveniences such as parentheses matching, tab-completion, tool-tip help popups, and a spreadsheet-like data viewer.

Install rstudio-desktop-binAUR (binary version from the Rstudio project website) or rstudio-desktop-gitAUR (development version) from AUR.

The R library path is often configured with the R_LIBS environment variable. RStudio ignores this, so the user must set R_LIBS_USER in ~/.Renviron, as documented above.

Rstudio server

RStudio Server enables you to provide a browser based interface to a version of R running on a remote Linux server.

Install rstudio-server-gitAUR. The two main configuration files are /etc/rstudio/rserver.conf and /etc/rstudio/rsession.conf. They are not created during the install, so you will need to create and edit them. For information about configure options, please refer to rstudio getting started documentation.

To start the server, please enable and start the rstudio-server.service unit file provided with the package.

Emacs Speaks Statistics

emacs users can interact with R via the emacs-essAUR package.

Nvim-R

The nvim-rAUR package allows vim and neovim users to code in R, including editing and rendering of R markdown (Rmd) files, execution of R code in a separate pane, inspection of variables, and integrated help panes.

Cantor

cantor is a notebook application developed by KDE that includes support for R.

Jupyter notebook

jupyter-notebook is a browser based notebook with support for many programming languages. R support can be added by installing the IRkernel.

Optimized packages

The numerical libraries that comes with the R (generic blas, LAPACK) do not have multithreading capabilities. Replacing the reference blas package with an optimized BLAS can produce dramatic speed increases for many common computations in R. However the available optimized BLAS packages all have drawbacks such as requiring a commercial license or potentially interfering with the standard R functionality for parallel processing. If you really need faster linear algebra in R you may consider the following options.

OpenBLAS

openblasAUR can be installed from the AUR, replacing the reference blas from extra. If you are using the regular r package from extra no further configuration is needed; R is configured to use the system BLAS and will use OpenBLAS once it is installed.

Intel MKL

If your processors are Intel, it is strongly advised to use the Intel math Kernel Library. The MKL, beyond the capabilities of multithreading, also has specific optimizations for Intel processors, with performance far superior to traditional libraries.

Please first Install the intel-mklAUR package available from AUR, then the r-mklAUR package.

Note:
  • if you install the r-mklAUR with R already installed, you will be prompted to remove R. Once r-mkl is installed, please run on R console the following command :

> update.packages(checkBuilt=TRUE)

  • here are elapsed time in sec from computing 15 tests with default GCC build and icc/MKL build: 274.93 sec for GCC build, 21.01 sec for icc/MKL build. See this post for more information.

intel-advisor-xe

intel-advisor delivers top application performance with C, C++ and Fortran compilers, libraries and analysis tools.

Install the intel-advisor-xeAUR[broken link: package not found] package.

See also

  • RSeek A search engine for R related material.