Install and configure the R program in Redhat and redhat.
This is mainly because of some basic problems I encountered when trying to use R under Redhat. I have read many articles and recorded and kept my process.
1. Install R
There are two ways to install the R program under Redhat. First, download, compile, and install the SDK using yum.
Install yum
If your yum source can be used normally, you can run the following command:
yum install R
Source code Installation
You may need to define some installation items by yourself. You can select source code for installation. However, yum can automatically help you download and install the dependency package. When directly installing the source code, you must ensure that all the dependent installation packages are installed properly. Some Dependent packages that need to be installed before R installation are mainly the gcc compiler and the command line editing library.
See http://segmentfault.com/a/1190000000662687.
Yum install gcc-gfortranyum install gcc-c ++ yum install readline-develyum install libXt-devel # networking, download the R Software wget Plugin-zxvf R-3.2.0.tar.gz # unzip to the current path cd R-3.2.0 # The prefix parameter can be set to the path where R will be installed, # enable-R-shlib ensures that the dynamic libraries under the lib directory can be shared. /configure -- prefix =/usr/R-3.2.0 -- enable-R-shlibmakemake install
In brief,./configure generates Makefile to prepare for the next compilation. You can set some required parameters. Make is compilation, and make install is installation.
See http://www.linuxidc.com/linux/2011-02/32211.htm.
2. Configure the environment
The preceding step cannot be used directly after installation. You need to configure the R environment. Direction ~ /. In the bash_profile file, add the bin PATH of R under the PATH, for example, the PATH to be added under my computer is/usr/R-3.2.0/bin, pay attention to the use of environment variables in Linux system ": ", you must remember the source after the configuration is complete.
Vim ~ /. Bash_profile # PATH =/usr/R-3.2.0/bin: $ PATH: $ HOME/binsource ~ /. Bash_profileecho $ PATH # Check whether the PATH is configured successfully
3. Simple Test
It is very easy to check whether your R is successfully installed. You can directly run the R command to enter the R operation interface. Now, R can be used normally.
R # Linux operation command print ("R has been successfullyinstalled.") # Enter
4. Run the R script
There are two ways to run the R script directly using command lines: r cmd and Rscript. The difference is that r cmd does not run in the background and Rscript outputs at the foreground. For more detailed usage, see references. Run the R script in the R program using the source () method.
See http://www.360doc.com/content/11/1201/22/5013584_169013651.shtml.
R cmd batch/usr/R-3.2.0/workspace/test. R <span style = "font-family: Arial, Helvetica, sans-serif;"> # Linux operation instructions </span> Rscript "/usr/R-3.2.0/workspace/test. R "<span style =" font-family: Arial, Helvetica, sans-serif; & gt; # Linux operation command </span> source (& quot;/usr/R-3.2.0/workspace/test. R ") <span style =" font-family: Arial, Helvetica, sans-serif; "> # input in R operation interface </span>
The content of test. R is as follows:
#! /Usr/R-3.2.0/workspacesetwd ("/usr/R-3.2.0/workspace ") print ("##################################### ") print ("# I'm a happy test program! #") Print ("##################################### ")
5. R porting
I used to work with R in windows. Recently, I had to switch to Redhat. However, many software packages were not required for the newly installed R, I checked that there are 118 software packages installed on R on my computer, but only 31 software packages were installed on R on Redhat, which are the default installation items when installing the program. It is difficult to install packages one by one as usual. Therefore, we have found a suitable method for various solutions.
Final reference: Appendix H of R language practice
FirstOn the R of your computer:
oldip <- installed.packages()[,1]save(oldip,file="installedPackages.Rdata)
ThenFind installedPackages in the R directory of your computer. rdata file, upload to Redhat under the R working directory you set (Redhat, default working directory is/root), I here is/usr/R-3.2.0/workspace.
LastRun the R script emigrate. R under Redhat. The script content is as follows:
#!/usr/R-3.2.0/workspacesetwd("/usr/R-3.2.0/workspace")load("installedPackages.Rdata")newip <- installed.packages()[,1]for(i in setdiff(oldip,newip))install.packages(i)
Some Packages may fail to be installed. You need to configure the environment or manually download the source code to install the package. view the warnings () information.
If you have any questions, please contact us!
Please indicate the source for reprinting. Thank you!