Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Rtools And R
#1

If you are compiling a package from source than you will need RTools. I was reading the book,"Statistical Analysis of Financial Data In R". The book has got an R package that is available on R Forge as a source package or binary package. It is not available on the standard CRAN. I wanted to install the binaries. When I tried to install it, I got the message that R will need to compile the C/C++/Fortran binaries. I would need Rtools for that. Rtools is separate from R. So I download it and installed it on my computer. I have installed R on my D drive in the folder Program Files. I installed Rtools on the same D drive Program Files Folder. Now I try and find the following error:

> install.packages("D:/Shared/R/Rsafd_1.2.tar.gz",repos=NULL,
+ type="source")
In R CMD INSTALL
* installing *source* package 'Rsafd' ...
** libs
c:/Rtools/mingw_64/bin/g++  -I"D:/Program Files/R/R-3.5.1/include" -DNDEBUG          -O2 -Wall  -mtune=generic -c empirfunc.cpp -o empirfunc.o
sh: c:/Rtools/mingw_64/bin/g++: No such file or directory
make: *** [D:/Program Files/R/R-3.5.1/etc/x64/Makeconf:215: empirfunc.o] Error 127
ERROR: compilation failed for package 'Rsafd'
* removing 'D:/Program Files/R/R-3.5.1/library/Rsafd'
Warning message:
In install.packages("D:/Shared/R/Rsafd_1.2.tar.gz", repos = NULL,  :
  installation of package 'D:/Shared/R/Rsafd_1.2.tar.gz' had non-zero exit status

Now Error 127 means R is unable to do the compilation. On close examination I find R trying to find Rtools on the C Drive. I change the Environment Variable path on Windows and find that it is correctly pointed to D Drive Program Files Rtools folder. What's the problem then? I search google and find the R has a file:

> file.path(R.home("etc"), "Makeconf")

[1] "D:/Program Files/R/R-3.5.1/etc/Makeconf"

This Makeconf file has been hard wired into looking for the Rtools on the C Drive c:/Rtools/mingw_64/bin/g++. There is a variable BINPREF that needs to be added to the Environment Variables that will override the default Makeconf file settings. So I add this Environment Variable:

BINPREF=D:\Program Files\Rtools\mingw_$(WIN)\bin\

I do that. Now R knows where to find Rtools in the new location but again it is stuck and can't find the files as there is a space in the Program Files and it cannot go beyong D:\Program. After doing the search on Google. I find the solution that I need to reinstall Rtools to a folder that hasn't got a space in it. So I install Rtools to the Stuff folder on D Drive and now I don't add the BINREF environment variable. I can do that but I change it for the current R session with the command:

Sys.setenv(BINPREF="D:/Stuff/Rtools/mingw_$(WIN)/bin/")

This command works and tells R that use this BINPREF for the session. I again run the install.packages command and viola the source package gets compiled and everything starts working nicely. I have made this thread so that anyone who is facing the same problem can easily solve it now. Rtools needs to be recognized by R before R can use it to compile package binaries. The most important thing is the BINPREF variable that needs to be properly set. $WIN in the above command ensures that it properly recognize whether your system is 32 or 64. Once you have done that R will have no problem whatsoever using Rtools in compiling source packages. With the R command Sys.setenv(0 above we don't need to add the environment variable BINPREF. If you want to add the BINPREF to the environment, add the following environment variable:

BINPREF=D:\Stuff\Rtools\mingw_$(WIN)\bin\

In the same manner you can use the following command to add the Rtools to the path:

Sys.setenv(PATH = paste("D:/Stuff/Rtools/bin", Sys.getenv("PATH"), sep=";"))

You can also check the path variables with the following command:

Sys.getenv()['PATH']

Now these were a little tips when you install Rtools on a drive different than C. If you install it on C than R will immediately recognize it otherwise you will have to use the above tricks to make R recognize the new Rtools location. R is a robust software and I think it is much better than Python when it comes to installation and management. I now check whether I can call Rsafd:

> library(Rsafd)
Loading required package: MASS
Loading required package: mvtnorm
Loading required package: robustbase
Loading required package: quantreg
Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

    backsolve

Loading required package: splines
Loading required package: timeDate
Loading required package: rgl

Attaching package: 'Rsafd'

The following objects are masked from 'package:mvtnorm':

    dmvnorm, rmvnorm

If you are interested in reading Statistical Analysis of Financial Data in R, you can safely install its package Rsafd.

Subscribe My YouTube Channel:
https://www.youtube.com/channel/UCUE7VPo...F_BCoxFXIw

Join Our Million Dollar Trading Challenge:
https://www.doubledoji.com/million-dolla...challenge/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)