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

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.

Related

Rserve : ld: library not found for -lssl

I am getting an error while trying to install Rserve 1.8.6. I can successfully install 1.7.3 from CRAN. This is on Mac OS High Sierra.
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [forward] Error 1
make: *** [all] Error 2
ERROR: compilation failed for package ‘Rserve’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rserve’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rserve’
The downloaded source packages are in
‘/private/var/folders/v7/hyxrfmk94p1_03gdrm27fnxncy3vq1/T/RtmpFHKNMe/downloaded_packages’
This worked for me (MacOS):
In terminal:
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
I'm running Mac OS 10.15 Catalina, I've spent 2 days trying to fix this same problem, scouring the internet for help. I finally managed it by cobbling together solutions from a few different sources.
The key thing I was missing was that Mac OS ships with its own version of openssl which it thinks is superior to anything else you can find. It is wrong. What you need to do is go and download the latest version of openssl, install that, then export THAT library to your library path variable. Here are the steps I took with openssl 1.1.1:
Get the version number for the latest version of openssl from the source (https://www.openssl.org/source/) and then manually install it directly where it's supposed to go:
cd /usr/local/src
If you're getting "No such file or directory", make it:
cd /usr/local && mkdir src && cd src
Download openssl using curl (shown) or using the link above to the source code (make sure you put the file in the directory you just made in the previous step):
curl --remote-name https://www.openssl.org/source/openssl-1.1.1f.tar.gz
Extract and cd in:
tar -xzvf openssl-1.1.1f.tar.gz
cd openssl-1.1.1f
Compile and install (these are the 64 bit Mac OS instructions. Refer to the openssl documentation for 32 bit and other OS instructions):
./Configure darwin64-x86_64-cc shared enable-ec_nistp_64_gcc_128 no-ssl2 no-ssl3 no-comp --openssldir=/usr/local/ssl/macos-x86_64
make depend
sudo make install
This created a new openssl folder so when you export the library path you have to feed it the right openssl folder:
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl#1.1/lib/
Hope that helps you if you haven't figured it out yet, and anyone else in the future who is ready to chuck their computer across the room, like I was.

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?

Installing R 3.0.2 in Ubuntu 16.04

I'm having trouble trying to install R 3.0.2 in Ubuntu 16.04. I tried adding the repositories of older versions of R but the package for R 3.0.2 cannot be found in apt-get. Has anyone tried installing an older version of R on a newer version of Ubuntu? May I know what the steps are?
I tried also specifying the version in the apt-get install command but it didn't find the right package.
I see the best option in your case is to compile R. If you have never done such a thing, follow this little script in terminal:
# install common R dependencies
sudo apt-get install gcc \
g++ \
gfortran \
bzip2 \
libbz2-dev \
xorg-dev \
liblzma-dev \
libreadline-dev \
libpcre++-dev \
libcurl-dev \
libpango1.0-dev
mkdir R_alternatives
cd R_alternatives
mkdir src
mkdir 3.0.2
cd src
wget https://cran.r-project.org/src/base/R-3/R-3.0.2.tar.gz
tar -xvf R-3.0.2.tar.gz
cd R-3.0.2
#In my opinion is better to compile in one folder (avoid uncompress tar.gz source again, if you get any errors)
mkdir BuildDir
cd BuildDir
# this step will take around 2 minutes
./../configure --with-readline=no --with-x=no --prefix=/home/'user'/R_alternatives/3.0.2
# These two will take longer!!
make
make install
# following the prefix in 'configure' your R libraries are going to be installed in /home/'user'/R_alternatives/3.0.2/lib64/R/library/
# Hence, each time you compile a new R version, it will have its own libraries (this avoid R packages versions problems)
# If you wish more than one library version for the same R version, you must create a new folder and then run
export R_LIBS=/'path_to_your_new_folder'
# If you plan to use this R version in RStudio, you have to edit ~/.bash_profile, therefore you must run:
vi ~/.bash_profile
#or, It is up to you!
gedit ~/.bash_profile
#Then you put this line in end of the file
PATH=/home/'user'/R_alternatives/3.0.2/bin:$PATH
export PATH
# OR...
RSTUDIO_WHICH_R=/home/'user'/R_alternatives/3.0.2/bin/R
export RSTUDIO_WHICH_R
#PS: You can also set the R_LIBS here, in the same way!
First off, see here for a similar & older question on SO.
Pre-compiled binaries of older R releases for various Ubuntu versions (mostly the LTS releases) are available as deb's from the following website:
https://cran.r-project.org/bin/linux/ubuntu/
Unfortunately, there doesn't seem to exist a R 3.0.2 deb package for xenial; only precise still has the R 3.0.2 package. You could try to install the precise package in xenial, but that may come with its own problem set.
Might be best to compile from source following Facottons advice.

Install R from source

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.

GLPK: No such file or directory error when trying to install R package

I am trying to install sparkTable in R 3.1.0 which depends on Rglpk. I manually installed GPLK on the system and added the libs folder to LD_LIBRARY_PATH before going into R for the install.packages("sparkTable") procedure. I get this error during the installation process. Any ideas?
* installing *source* package ‘Rglpk’ ...
** package ‘Rglpk’ successfully unpacked and MD5 sums checked
** libs
/bin/sh: line 0: cd: GLPK: No such file or directory
make: *** [GLPK.ts] Error 1
ERROR: compilation failed for package ‘Rglpk’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/Rglpk’
ERROR: dependency ‘Rglpk’ is not available for package ‘sparkTable’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/sparkTable’
sudo apt-get install libglpk-dev
did the trick for me.
I had this problem and took a good bit of digging in the package to understand what was happening. If Rgplk can't compile its test program when installing, it does something weird, including this bizarre cd to nowhere. Assuming glpk-devel is installed, the reason it can't compile the test program is that it can't find the gplk header as it is in a non-standard directory.
Just set the environment variable CPATH=/usr/include/glpk
and the test program will compile, allowing the package install to proceed normally.
I had this problem too. The following steps solved this issue for me. My current setup:
OS: Scientifc Linux version 6.5 (on a High Performance Cluster Server)
local user, no root access.
GLPK was not installed
Install GLPK in a local directory:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=/home/<username>/GLPK
make
make install
Install Rglpk (0.6-3):
cd ~
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-3.tar.gz
export LIBRARY_PATH=/home/<username>/GLPK/lib
R CMD INSTALL Rglpk_0.6-3.tar.gz
I landed on this page, because I could not update igraph under Windows 10/11, since igraph also requires glpk as per OP. Specifically:
igraph_glpk_support.h:36:10: fatal error: glpk.h: No such file or
directory #include <glpk.h>
^~~~~~~~ compilation terminated. make: *** [C:/PROGRA~1/R/R-4.1.1/etc/x64/Makeconf:238: feedback_arc_set.o] Error
1 ERROR: compilation failed for package 'igraph'
removing 'C:/Users/xxx/Documents/R/win-library/4.1/igraph'
restoring previous 'C:/Users/xxx/Documents/R/win-library/4.1/igraph' Warning
in install.packages : installation of package ‘igraph’ had non-zero
exit status
I am under Windows 11 (but would be same for Windows 10).
Simple resolution is suggested here:
start Rtools Bash (found in all apps, Rtools 4.0 in the Windows menu)
Run pacman -S mingw-w64-x86_64-glpk and confirm with yes (y)
Run pacman -S mingw-w64-x86_64-libxml2 and confirm with yes (y)
Updating igraph in Rstudio now leads to a clean
DONE (igraph)
(there is no need to install anything, add any path, etc... just the above 4 steps)
In ubuntu 14.04, all above doesn't work. the following however works, without the need of installing libglpk-dev using apt-get.
download the glpk package from gnu and extract it:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.55.tar.gz
tar xvf glpk-4.55.tar.gz
make a GLPK directory in your local path:
mkdir ~/GLPK
configure within glpk:
cd glpk-4.55
./configure --prefix=$HOME/GLPK
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
download the Rglpk package from cran and extract it:
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-0.tar.gz
tar xvf Rglpk_0.6_0.tar.gz
move the glpk directory into Rglpk/src and rename it to GLPK:
mv glpk-4.55 Rglpk/src/GLPK
now you can install:
R CMD INSTALL Rglpk
now a bit of explanation of what's going on. The "src/Makevars.in" file in the Rglpk package contains a line of code to enter a non-existing directory 'GLPK' within the src/ folder:
(line 11 of Makevars.in)
GLPK.ts:
#(cd GLPK && make)
touch $#
this is where the problem arises. obviously the code is trying to build glpk within that directory for some unknown reasons. and the solution above is achieved simply by moving the downloaded (and configured) glpk directory there...
If you're on a Debian-based Linux distribution, run this to install GLTK:
sudo apt install libglpk-dev
If you're on MacOS, run this to install GLTK:
brew install gltk
Finally, install the R library:
install.packages("Rglpk")
On Centos, have sudo rights. None of the above worked, but had to install GLPK in /usr/local as suggested in this SO answer. Been trying to install it for about 3 hours fml
You must install glpk dependency first.
On macOS (via homebrew):
brew install glpk
or in RStudio (via homebrew):
system("brew install glpk")
It worked for me when I combined the answers from Simón Ramírez Amaya and shadowleaves:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=$HOME/GLPK
make
make install
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
wget https://cran.r-project.org/src/contrib/Rglpk_0.6-4.tar.gz
R CMD INSTALL Rglpk_0.6-4.tar.gz
To load the library
dyn.load(file.path(Sys.getenv("HOME"), "GLPK", "lib", "libglpk.so"))
library(Rglpk)
The answer of Zhiying Cui is right, however, if your script has some special codes, such as foreach for parallel computing, it may raise an error.
A better way is as fellow
If your os is Centos, try
yum install glpk-devel
then just go to R or Rstudio server and
install.packages("Rglpk")

Resources