Install R from source - r

I'm trying to install R from source in my home directory on a server running CentOS.
I do not have root rights, and I'm not permitted to write to `usr/local/include/'.
I use the following code:
wget http://cran.rstudio.com/src/base/R-3/R-3.2.0.tar.gz
tar xvf R-3.2.0.tar.gz
cd R-3.2.0
./configure --prefix=$HOME/R
In configuration step, I get error
configure:error:--with-readline=yes (default) and headers/libs are not available
In my understanding, it tells me that readline library is not available.
So I try to install readline.
I downloaded tar.gz file. and then I use the following command
tar xvf readline-6.3.tar.gz
cd readline-6.3
./configure --prefix=$HOME/readline
make
make install
Things are fine, and there's an additional folder in my home directory named "readline".
When I go back and try to configure R again, I still get the same error message. How can I fix it?

Try using these flags for your ./configure script
CXXFLAGS="-ggdb -pipe -Wall -pedantic -I/path/readline/6.3/include"
CPPFLAGS="-I/path/readline/6.3/include"
LDFLAGS="-L/path/readline/6.3/lib"
Then if you get an error about X11, set --with-x=no and try again.

Related

Installing R on OSX Big Sur (EDIT: and Apple M1) for use with Rcpp and openMP

There's probably a gazillion threads on OSX+Rcpp+openMP, but the bottom line right now appears to be this (per coatless):
Unfortunately, with R 4.0.0 the CRAN distributed version of R loses
the ability to use OpenMP without a custom setup.
I came across other ideas, including compiling llvm yourself, using homebrew or macports to install R and/or llvm and/or gcc, and then figuring out how to use the right compiler and/or flags with (R)cpp. However, I find this all very confusing.
I am not a mac user, but it seems to me that setting up a mac to compile Rcpp packages or code snippets with openMP seems to be too difficult for most mac users. However, I would like my R package on github to be used by more users, and since it relies on openMP, I am losing that audience.
Can someone provide the necessary steps to set up R on mac in a way that it can compile Rcpp code with openMP? I'd like to turn that into a quick tutorial.
EDIT: I should have added - on Apple Silicon, because there are some extra confusions where things go - /usr/local vs /opt
I spent a day figuring this out (original post here); here are the steps I used to compile R packages from source with openMP:
Install xcode from the app store (instructions for installing xcode) then install/reinstall the xcode command line tools from the terminal:
# To delete an existing command line tools installation:
sudo rm -rf /Library/Developer/CommandLineTools
# To install the command line tools
sudo xcode-select --install
Install gcc via Homebrew (instructions for installing Homebrew) or, if you already have gcc installed, skip to step 3.
# WARNING: This can take several hours
brew install gcc
To avoid "legacy" version issues:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
Link some headers into /usr/local/include
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
# You can ignore warnings like this:
#ln: /usr/local/include//tcl.h: File exists
#ln: /usr/local/include//tclDecls.h: File exists
#ln: /usr/local/include//tclPlatDecls.h: File exists
#ln: /usr/local/include//tclTomMath.h: File exists
#ln: /usr/local/include//tclTomMathDecls.h: File exists
#ln: /usr/local/include//tk.h: File exists
#ln: /usr/local/include//tkDecls.h: File exists
#ln: /usr/local/include//tkPlatDecls.h: File exists
Check your version of gfortran (cd /usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/; ls) then edit your ~/.R/Makevars file (if you don't have a file called Makevars in your ~/.R/ directory) and include only these lines:
LOC = /usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/bin/g++ -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
# (check that the version of gfortran - in this case 10.2.0 - matches the version specified in FLIBS)
FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++
Open R and install a package to test that it compiles with openMP enabled (when asked, compile from source = "Yes"):
install.packages("data.table", type = "source")
Unfortunately, I do not believe a more "simple" setup exists.
Eventually, I found a process that works on a M1 mac with Big Sur.
Head over to https://mac.r-project.org/, it contains most things you will need
Download and install R via R-4.1-branch.pkg. The CRAN version might also work, but I used the installer from mac.r-project.org, which required opening the osx security settings to allow the installation.
Install RStudio, start it, and let it install the developer tools. Alternatively, run sudo xcode-select --install in Terminal.
Head to https://mac.r-project.org/openmp/. Download openmp-11.0.1-darwin20-Release.tar.gz and install it (see Terminal commands below).
curl -O https://mac.r-project.org/openmp/openmp-11.0.1-darwin20-Release.tar.gz
sudo tar fvx openmp-11.0.1-darwin20-Release.tar.gz -C /
Now we need to add compiler flags so that clan uses openMP. In Terminal, create the Makevars file.
cd ~
mkdir .R
nano .R/Makevars
in nano, paste these additional compiler flags into the Makevars file:
CPPFLAGS += -Xclang -fopenmp
LDFLAGS += -lomp
Hit Control+O, Control+X to save and close
Head over to the gfortran page: https://github.com/fxcoudert/gfortran-for-macOS/releases
Use the installer gfortran-ARM-11.0-BigSur.pkg to install gfortran.
For some reason it appears to install in /usr/local/gfortran, but R expects it in /opt. The mac-R team likes to separate arm64 and intel related files. We could go and fix paths, or simply also install gfortran under /opt. Download the tar file gfortran-ARM-11.0-BigSur.tar.xz. You can use curl, or just download it and point tar in the command line to it.
cd /opt/R/arm64/
sudo mkdir gfortran
sudo tar -xzyf gfortran-ARM-11.0-BigSur.tar.xz -C /opt/R/arm64/
(replace gfortran-ARM-11.0-BigSur.tar.xz with /users/YOURUSERNAME/downloads/gfortran-ARM-11.0-BigSur.tar.xz)
Now it should work.
Not an expert in OSX, but doing this so others can figure out how to use my R package. I'd like to streamline the process some more, but wiping the mac, reinstalling osx and testing it takes so much time.

Install Emacs without root privilege under my personal directory, error while running ./configure --prefix -my-personal-directory

I am using system RedHat 6.8 and I tried to install emacs under my personal directory as I don't have permission to run root command.
Below is my command:
cd emacs-24.5
./configure --prefix -my-home-directory
Then I got error message as below:
configure: error: The following required libraries were not found:
libXpm libgif/libungif libtiff
Maybe some development libraries/packages are missing?
If you don't want to link with them give
--with-xpm=no --with-gif=no --with-tiff=no
as options to configure
I did some google search and it told me I need to install dependence libXpm, libgif/libungif and libtiff, but all instructions online were teaching you how to install these dependence with root privilege, which I don't have.
Then I downloaded source code of libXpm from https://xorg.freedesktop.org/archive/individual/lib/ and run following command
tar xvf libXpm-3.5.12.tar.gz
cd libXpm-3.5.12
configure --prefix -my-home-directory
make
make install
Then the libXpm successfully installed and I also appended the path to the libXpm in $LD_LIBRARY_PATH by
export LD_LIBRARY_PATH=/path/to/libXpm:$LD_LIBRARY_PATH
However, after that I tried to ./configure emacs again it still output that error
configure: error: The following required libraries were not found:
libXpm libgif/libungif libtiff
Maybe some development libraries/packages are missing?
If you don't want to link with them give
--with-xpm=no --with-gif=no --with-tiff=no
as options to configure
Anybody can help me out?

Bash on Ubuntu on Windows, Run Linux Commands to Install a Windows Program

I am new to Linux, but I am having a lot of trouble installing an R package that does not have windows binaries. I would rather not install a full Linux install and move everything. Judging by Windows Interoperability it seems like this should be possible.
I want to do any one of the options from the GNU R package cplexAPI documentation below in the block quote. I have tried:
C:\Users\zejas>bash
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ R CMD INSTALL cplexAPI_1.3.2.tar.gz
The program 'R' is currently not installed. You can install it by typing:
sudo apt-get install r-base-core
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$
Based on the example:
$/mnt/c/Windows/System32/notepad.exe
I have tried:
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ $/mnt/C/Program Files/Microsoft/MRO-3.3.1/bin
bash: $/mnt/C/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/C/Program Files/Microsoft/MRO-3.3.1/bin
bash: /mnt/C/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: /mnt/C/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ $/mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: $/mnt/C/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: C/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ $/mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: $/mnt/C/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: /mnt/C/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/c/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: /mnt/c/Program: No such file or directory
zejas#DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/c/Windows/System32/notepad.exe
bash: /mnt/c/Windows/System32/notepad.exe: cannot execute binary file: Exec format error
Any ideas?
----------------------------------------------------------------------------
Linux and MacOS X installation
----------------------------------------------------------------------------
The locations of the CPLEX callable library and the CPLEX include
directory can be found in /README.html>, where
is the CPLEX installation directory. Also have a look at the
variables CLNFLAGS and COPT in the example Makefile of your CPLEX
installation. There, the variable CPLEXLIBDIR points to the callable
library directory.
There are several ways of installing the cplexAPI package:
1) Set variables PKG_CFLAGS, PKG_CPPFLAGS and PKG_LIBS directly, e.g.:
R CMD INSTALL --configure-args =" \ PKG_CFLAGS='-m64 -fPIC' \
PKG_CPPFLAGS='-I/cplex/include' \
PKG_LIBS='-L${CPLEXLIBDIR} -lcplex -m64 -lm -pthread'" \
cplexAPI_x.x.x.tar.gz
PKF_CFLAGS is optional, but both PKG_CPPFLAGS and PKG_LIBS must be
given.
2) Use --with-cplex-:
--with-cplex-include=PATH with PATH being the include directory
of CPLEX
--with-cplex-lib=PATH with PATH being the directory
containing the
callable library of CPLEX.
R CMD INSTALL --configure-args=" \
--with-cplex-include=/path/to/include/dir \
--with-cplex-lib=/path/to/lib/dir" cplexAPI_x.x.x.tar.gz
When using --with-cplex-, both arguments --with-cplex-lib and
--with-cplex-include must be given.
--with-cplex-link=-l... libraries to path to the linker during
compilation.
If --with-cplex-link is not given, '-lcplex -lm -pthread' will be
used as default.
--with-cplex-cflags=... optional CFLAGS
A further argument can be used in order to use the debuging
routines included in the C API of CPLEX:
--with-cplex-check=PATH with PATH being the directory
containing the
file check.c from the CPLEX examples directory.
R CMD INSTALL --configure-args=" \
--with-cplex-lib='/path/to/lib/dir' \ --with-cplex-include='/path/to/include/dir' \ --with-cplex-link='-lcplex -m64 -lm -pthread' \ --with-cplex-cflags='-m64 -fPIC' \ --with-cplex-check='/path/to/examples/dir/examples/src/c'" \ cplexAPI_x.x.x.tar.gz
3) Give the location of the CPLEX installation:
--with-cplex-dir=PATH
with PATH being the CPLEX directory. This is not the CPLEX installation directory , it is the directory including
the lib/ include/ and examples/ directory. Usually this is
/cplex.
R CMD INSTALL --configure-args="
--with-cplex-dir='/cplex'" \ cplexAPI_x.x.x.tar.gz
This procedure will take the first system type and library format
it finds. Information reqired for the compilation is taken from the
example Makefile.
4) Give no information:
R CMD INSTALL cplexAPI_x.x.x.tar.gz
This procedure will try to find the CPLEX interactive optimizer, or the CPLEX_BIN environment variable pointing to the
CPLEX interactive optimizer will be used. The directory two levels
above is used as CPLEX directory, all other information is taken
from teh CPLEX example Makefile as in #3 above.
First, to access a path with spaces in it, use double quotes:
"/mnt/c/Program Files/Microsoft/MRO-3.3.1/bin/R.exe"
Second, you can only run Windows programs from bash if you have build 14951 of Windows 10 or later. This is noted at the top of the MSDN page you linked to:
The Windows Subsystem for Linux can invoke native Windows binaries and be invoked from a Windows command line. This feature is available to Windows 10 users running Anniversary Update build 14951.
This build is still in Windows Insider release, so isn't generally available yet (latest GA is build 14393 as of 16 Jan 2017). For now, you can install cbwin if you want this functionality.
Third, running R from a Linux shell won't magically solve the reason why a precompiled binary package isn't available: cplexAPI depends on the CPLEX Studio application from IBM, and you still need to have this available for the R package to work. Assuming you do have this available, you can download the cplexAPI source and compile the package from Windows, without touching the bash shell.

Connecting kdb+ to R

I'm trying to run a make file to install qserver on my OSX machine.
The make file gives me an error when I try to run. see code below:
make
/Library/Frameworks/R.framework/Resources/bin/R CMD gcc -g -O -fpic -m64 -shared -D KXVER=3 -I. -I/Library/Frameworks/R.framework/Resources/share/include base.c c.o -lpthread -L/Library/Frameworks/R.framework/Resources/share/lib -lR -o qserver.so
/Library/Frameworks/R.framework/Resources/bin/R: /Library/Frameworks/R.framework/Resources/bin/R: cannot execute binary file
make: *** [all] Error 126
Hoping someone can give me a pointer here on how to fix it.
Do you have the right version of gcc? I build with gcc-4.8 and have no issues. I recall a thread on the kdb list that mentioned the build required some features available only in later gcc versions. Give that a try.
[EDIT]
Nevermind, just saw that the error says the R binary was not found. Edit the make file to use the appropriate path for your R installation. If you don't have R installed, I suggest installing with homebrew:
brew tap homebrew/science
brew install r
After that you can replace the path in the Makefile as appropriate. I personally changed the Makefile to use $(shell R RHOME) to find the R home path, rather than assume a specific location.
JPC was partially right about gcc.
My system had two different versions of gcc loaded and the default was the standard one. I changed the makefile to run 'gcc-4.8'.
Once I finished that I got a new error: the make file couldn't locate my 'R.h' file...so i just had to reference where my r h-files were located....once I did that the make problem executed.

nginx install on linux

I downloaded nginx from it's site for linux(I use ubuntu 10.4).I extracted nginx-1.0.6.tar.gz and there was a configure file in that directory. So I entered "./configure" command in shell. It seemed to be configured right.After I entered "make" command ,It said this error:
make -f objs/Makefile
make[1]: Entering directory `/usr/local/nginx'
cd ./auto/lib/pcre/ \
&& if [ -f Makefile ]; then make distclean; fi \
&& CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared
/bin/sh: ./configure: not found
make[1]: *** [auto/lib/pcre//Makefile] Error 127
make[1]: Leaving directory `/usr/local/nginx'
make: *** [build] Error 2
what should I do now?
you have to install Dependencies .
generally these will be enough
libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
so you can first install them
sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
and then compile .. also make sure you run the make command as root.
The ./configure program of nginx wants to find either the shared libs to build nginx dynamicaly linked or the sources of openssl prce and zlib respectivly.
The obove mentioned error occurs when you invoke ../nginx/configure with the wrong options.
--with-pcre=/path/to/lib # where libpcre.a resides
--with-openssl=/path/to/lib # where libssl.a resides
--with-zlib=/path/to/lib # where libz.a resides
is wrong especially when ld.so has no idea about these libs
If you build a statically linked version of nginx
try instead
--with-pcre=/path/to/src/of/pcre
--with-openssl=/path/to/src/of/openssl
--with-zlib=/path/to/src/of/zlib
e.g.
--with-pcre=../pcre-8.36 --with-openssl=../openssl-1.0.2 --with-zlib=../zlib-1.2.8
Download PCRE from source
Unzip it (do not install)
Copy this path to configure (from Downloads folder)
./configure --with-pcre=/home/USER/DOWNLOADS/pcre-8.37/
Enter your nginx install directory - I solved this error by editing objs/Makefile and removing -Wall and -Werror params so it looks like this (second line):
CC = gcc
CFLAGS = -pipe -O -W -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -g
Also, running your ./configure should initiate a long procedure of verifications to ensure
that your system contains all the necessary components. If the configuration fails for any reason, check
less objs/autoconf.err
for more details. Any errors at configuration are usually based on missing dependencies for your configuration.
You didn't configure it right. Use these commands (in the nginx directory):
./configure --with-pcre=./auto/lib/pcre/ --with-zlib=./auto/lib/zlib/
./configure
make
sudo make install
Look for Ubuntu installation at http://wiki.nginx.org/Install.
Look for ubuntu/ centos installation at https://nodevine.com/library/installing-multiple-virtual-hosts-on-nginx-on-ubuntu-12-04-and-cent-os-6
We can now add the repository to install the latest version of nginx:
sudo add-apt-repository ppa:nginx/stable
Note: If this command still does not work (normally on 12.10), run the following command:
sudo apt-get install software-properties-common
This will add the repository to Ubuntu and fetches the repository's key. This is to verify that the packages have not been interfered with since they have been built.
Step Three - Updating the Repositories
After adding a new repository, you will need to update the list:
sudo apt-get update
Install nginx
To install nginx or update the version you already have installed, run the following command:
sudo apt-get install nginx
Check That Nginx is Running
You can check to see that nginx is running by either going to your VPS' IP address/domain, or typing in:
service nginx status
This will tell you whether nginx is currently running.
with a vps debian wheezy
I have to install a lot of tools in order to install nginx 1.2.9 :
apt-get install libpcre3 libpcre3-dev
apt-get install --reinstall zlibc zlib1g zlib1g-dev
apt-get install make
apt-get install sudo

Resources