error using R package brms - r

I would like to use the R package brms, but I get an error that I do not manage to interpret. It might have to do with Rtools, which is however installed on my computer.
This is an example from the brms package:
fit1 <- brm(count ~ log_Age_c + log_Base4_c * Trt_c
+ (1|patient) + (1|visit) + (1|obs),
data = epilepsy, family = poisson(),
prior = c(set_prior("student_t(5,0,10)", class = "b"),
set_prior("cauchy(0,2)", class = "sd")))
And this is the error I get:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created!
c:/Rtools/mingw_64/bin/g++: not found
make: *** [file202834c75e9.o] Error 127
Warning message:
l'exécution de la commande 'make -f "C:/PROGRA~1/R/R-33~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.0/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file202834c75e9.dll" WIN=64 TCLBIN=64 OBJECTS="file202834c75e9.o"' renvoie un statut 2
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-33~1.0/bin/x64/R CMD SHLIB file202834c75e9.cpp 2> file202834c75e9.cpp.err.txt' had status 1
Thanks for your help

Indeed, it is a problem with Rtools. What does system("g++ -v") give you? If it is status 127, Rtools cannot be found by R. Most likely, you haven't checked the box during Rtools installation where you were asked to amend the system path. I suggest that you unintall Rtools and install it again making sure to check the box. Please also verify that you are using the correct version of Rtools compatible with your R version.

I had a similar problem with my installation of rstan. The problem occurred with RTools33. Installing RTools34 seemed to fix the problem, although I now get the following warning:
In find_rtools() :
WARNING: Rtools 3.4 found on the path at c:/Rtools is not compatible with R 3.3.1.
Please download and install Rtools 3.3 from http://cran.r-project.org/bin/windows/Rtools/, remove the incompatible version from your PATH, then run find_rtools().
So far this warning appears benign.

If none of the other answers solve this issue, go into your R distribution and open
R-{version}\etc\x64\Makeconf
and change BINPREF on line 19 to whatever the path to your mingw_64\bin directory is.

To fix this error:" c:/Rtools/mingw_64/bin/g++: not found" I located RBuildTools folder on the C: drive, found the g++ file in the bin folder, copied the mingw_64 folder (or wherever your g++ file is located), created an Rtools folder on C: and pasted the mingw_64 folder. This will create the C:/Rtools/mingw_64/bin/ path you need to compile R code using the stan( ) function.

I followed the rStan wiki here on Windows Configuration.
Also instead of hacking Makevars in c:\ you can create your personal by following the instruction here.
In my %HOM%\.R\Makevars.win64 file I have
CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function
BINPREF="H:/RTools/mingw_64/bin/"
This resolved my issue.

Related

Error when compiling RInside examples on Windows

I have an issue compiling the RInside examples on Windows.
In Rstudio, running
sourceCpp("C:/Users/Admin/Documents/R/win-library/3.5/RInside/examples/standard/rinside_sample0.cpp")
gives
fatal error: RInside.h: No such file or directory
From the command promt, running
cd C:\Users\Admin\Documents\R\win-library\3.5\RInside\examples\standard
make -f Makefile.win rinside_sample0
gives
Error in loadNamespace(name) : aucun package nommé 'Rcpp' n'est trouvé
Error in loadNamespace(name) : aucun package nommé 'RInside' n'est trouvé
Apparently these packages are not found, so I tried the following:
Ran this from the command line set R_HOME=C:\Program Files\R\R-3.5.2
Checked that Rtools and R dirs are present in the path
Modified the Makefile.win like so:
R_LIBS_USER := "C:/Users/Admin/Documents/R/win-library/3.5"
R_ARCH := --arch x64
But still getting the same errors. Any help? Thanks
EDIT: this answer might provide a solution by including this line of code somewhere
export R_LIBS_SITE=c:/R/site-library
However I don't know where to include it.
EDIT2 I have tried to reinstall Rcpp and RInside in both library locations (by running RStudio as admin)
remove.packages("Rcpp", lib = .libPaths())
remove.packages("RInside", lib = .libPaths())
install.packages("RInside", lib = .libPaths())
install.packages("Rcpp", lib = .libPaths())
library("RInside")
library("Rcpp")
In RStudio I still have the same error using sourceCpp, however, using the comand prompt and make approach I do get a different error:
make -f Makefile.win rinside_sample0
g++.exe: error: Files/R/R-3.5.2/library/RInside/include: No such file or directory
I suppose the space in the path is the problem " Files..." will try to reinstall R in a non-spaced path
Reinstalling R in a path without spaces, installing the latest packages, and setting R_HOME environment variable to the new installation folder C:\R\R-3.5.2 solved the problem.
remove.packages("Rcpp", lib = .libPaths())
remove.packages("RInside", lib = .libPaths())
install.packages("RInside", lib = .libPaths())
install.packages("Rcpp", lib = .libPaths())
library("RInside")
library("Rcpp")

R : C++11 standard requested but CXX11 is not defined

I am using a Linux system x86_64-redhat-linux-gnu-library with a CentOS server.
The R version is 3.4.1
When installing the package "pdftools" I get the following error :
Error in .shlib_internal(args) :
C++11 standard requested but CXX11 is not defined
Has anyone encountered the problem?
Doing the following worked for me:
Under /usr/lib64/R/etc there are 2 Makeconf files:
Makeconf
Makeconf.rpmnew
Backup the 'Makeconf' file and replace it with the contents of 'Makeconf.rpmnew'
Found the solution here (wch's answer):
https://github.com/rstudio/httpuv/issues/82

Installing R Interface for Ipopt

I have exactly the same problem as the poster here, unfortunately no solution is provided on that link.
I built and installed IPOPT (version 3.12.6) on Windows 7 (64bit) with Cygwin, but I cannot seem to get the R interface to work. All commands (configure, make, make install, make test) were executed without error.
When I try to build the R interface from RStudio, I tried using both the code in the "build" folder as well as the code in the main directory. I get the following errors:
`>install.packages("C:/cygwin64/home/Ipopt-3.12.6/build/Ipopt/contrib/RInterface",
repos=NULL, type="source")
Error:
cygwin64/home/Ipopt-3.12.6/build/Ipopt/contrib/RInterface/DESCRIPTION'
Not using the build directory:
`>install.packages("C:/cygwin64/home/Ipopt-3.12.6/Ipopt/contrib/RInterface", repos=NULL, type="source")
Error:
installing source package 'ipoptr' ...
** libs
*** arch - i386 Warning: running command 'make -f "Makevars.win" -f "C:/Users/~1/DOCUME~1/R/R-33~1.1/etc/i386/Makeconf" -f
"C:/Users/~1/DOCUME~1/R/R-33~1.1/share/make/winshlib.mk"
SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)'
SHLIB="ipoptr.dll" ' had status 127 ERROR: compilation failed for
package 'ipoptr'
* removing 'C:/Users/Documents/R/R-3.3.1/library/ipoptr' Warning in install.packages : running command
'"C:/Users/~1/DOCUME~1/R/R-33~1.1/bin/x64/R" CMD INSTALL -l
"C:\Users\Documents\R\R-3.3.1\library"
"C:/cygwin64/home/Ipopt-3.12.6/Ipopt/contrib/RInterface"' had status 1
Warning in install.packages : installation of package
‘C:/cygwin64/home/Ipopt-3.12.6/Ipopt/contrib/RInterface’ had non-zero
exit status
Does anyone know what I could do to resolve this?
EDIT: After installing RTools and adding it to my PATH I get ipoptr.cpp:22:34: fatal error: IpIpoptApplication.hpp: No such file or directory
#include "IpIpoptApplication.hpp", i.e. it seems that ipoptr.cpp cannot find IpIpoptApplication.hpp (which is in a subdirectory of the build folder) and later on in the error still the same Warning: running command 'make -f "Makevars.win" -f ' had status 2.... Copying this file over to the location of ipoptr.cpp moves the error one file further to another similar file that it cannot find. I suspect it cannot find these files because of something being wrong with my makevars.win file (I suspect that that's the file that should point to the currently missing files). Does anyone have an idea what this could be?
EDIT 2: Might it have to do with the comment here indicating that in some cases LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$IPOPTDIR/build/lib should be set? How do I do this? Should this be done in R or cygwin?

require(RQuantLib) fails

I am trying to load RQuantLib but I get the following error:
> require(RQuantLib)
Loading required package: RQuantLib
Error : .onLoad failed in loadNamespace() for 'RQuantLib', details:
call: if (is.character(qc) && nchar(qc) > 1) {
error: missing value where TRUE/FALSE needed
In addition: Warning message:
running command 'bash -c 'type -p quantlib-config' 2>/dev/null' had status 1
I am pretty new to programming in general so I am not sure what this means. I am working in an Mac OS Maverick environment, I downloaded the latest version of RQuantLib (0.3.12) and the "R Package Installer" says it is installed. (I installed RQuantLib from the terminal using "R CMD INSTALL RQuantLib" as using install.packages() from within R did not work - it gave me an error saying QuantLib was not configured, although it was running fine in from the terminal.) I am running R from the R console. QuantLib works fine and so does Rcpp.
I checked the "NAMESPACE" document in the RQuantLib folder and it says:
import(methods)
importFrom(Rcpp, Rcpp.plugin.maker)
useDynLib(RQuantLib)
exportPattern("*.default")
export(
##--arrays.R
"oldEuropeanOptionArrays",
"EuropeanOptionArrays",
"plotOptionSurface",
##--asian.R
"AsianOption",
##--bermudan.R
"BermudanSwaption",
"summary.G2Analytic",
"summary.HWAnalytic",
"summary.HWTree",
"summary.BKTree",
##--bond.R
"ZeroCouponBond",
"ZeroPriceByYield",
"ZeroYield",
"FixedRateBond",
"FixedRateBondYield",
"FixedRateBondPriceByYield",
"FloatingRateBond",
"ConvertibleZeroCouponBond",
"ConvertibleFixedCouponBond",
"ConvertibleFloatingCouponBond",
"CallableBond",
"FittedBondCurve",
##--calendars.R
"isBusinessDay", "businessDay",
"isHoliday",
"isWeekend",
"isEndOfMonth",
"getEndOfMonth", "endOfMonth",
"adjust",
"advance",
"businessDaysBetween",
"getHolidayList", "holidayList",
"setCalendarContext",
##--dayCounter.R
"dayCount",
"yearFraction",
"setEvaluationDate",
##--discount.R
"DiscountCurve",
"plot.DiscountCurve",
##--implied.R
"EuropeanOptionImpliedVolatility",
"AmericanOptionImpliedVolatility",
"BinaryOptionImpliedVolatility",
##--option.R
"EuropeanOption",
"AmericanOption",
"AmericanOption.default",
"BinaryOption",
"BarrierOption"
)
S3method("plot", "Option")
S3method("print", "Option")
S3method("summary", "Option")
S3method("plot", "Bond")
S3method("print", "Bond")
S3method("summary", "Bond")
If I try to specify the path where the Terminal wrote that it installed RQuantLib while requiring it I get the following error:
> require('RQuantLib', lib.loc = "C:/Users/dealmer/Library/R/3.1/library/RQuantLib/libs")
Loading required package: RQuantLib
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
no library trees found in 'lib.loc'
So, do I need to move something from there to where the other R libraries are? (There is already a folder named "RQuantLib" in the folder where the other R library folders are, that's where I found the NAMESPACE doc for example) The path that the Terminal gave me I can't follow in the Finder window however because it doesn't show the "Library" folder and I don't know how to make it do that.)
This is what .libPaths() gives me:
> .libPaths()
[1] "/Users/dealmer/Library/R/3.1/library"
[2] "/Library/Frameworks/R.framework/Versions/3.1/Resources/library"
The R libraries are in [2].
I've tried googling but I can't find anything that seems helpful. Any help will be very appreciated. Thank you
- Dom
I think the issue is that on Linux we have quantlib-config in the $PATH:
edd#max:~$ quantlib-config --help
Usage: quantlib-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] \
[--libs] [--cflags]
edd#max:~$ quantlib-config --version
1.4
edd#max:~$
I don't own an OS X box, so I depend on someone like you help with a better configure setup. It should just work if you copy (or soft-link) quantlib-config into your path (eg /usr/local/bin), or adjust $PATH otherwise to include the directory it is in.
I had the same issue and after some hours of struggle I manage to use something not very rigorous but it works!
It seems that R has some issues evaluating system("bash -c 'type -p quantlib-config'").
After having installed QuantLib, typing the command bash -c 'type -p quantlib-config' in Terminal gives us the path of our quantlib-config which is for me /opt/local/bin/quantlib-config.
So I went back to my source folder for RQuantLib (version 0.4.0) and replaced qc in file R/inline.Rby:
qc <- as.character("/opt/local/bin/quantlib-config")
and rebuilt the package using the terminal command R CMD install RQuantLib/.
As I said, not very sexy but it works.
A restart of R and Rstudio is necessary.
Hope it helps!

RQuantLib fails to load

I've recently updated all packages. Now RQuantLib fails to load. What can I do? I've tried to remove and reinstall the package in version 0.3.12 both from CRAN and from the source file, neither helps.
> library(RQuantLib)
Error : .onLoad failed in loadNamespace() for 'RQuantLib', details:
call: if (is.character(qc) && nchar(qc) > 1) {
error: missing value where TRUE/FALSE needed
In addition: Warning message:
running command 'bash -c 'type -p quantlib-config' 2>/dev/null' had status 1
Error: package or namespace load failed for ‘RQuantLib’
I'm working in RStudio with R 3.0.2 on Mac OS Mavericks. What can I do?
I had the same issue and after some hours of struggle I manage to use something not very rigorous but it works!
It seems that R has some issues evaluating system("bash -c 'type -p quantlib-config'").
After having installed QuantLib, typing the command bash -c 'type -p quantlib-config' in Terminal gives us the path of our quantlib-config which is for me /opt/local/bin/quantlib-config.
So I went back to my source folder for RQuantLib (version 0.4.0) and replaced qc in file R/inline.Rby:
qc <- as.character("/opt/local/bin/quantlib-config")
and rebuilt the package using the terminal command R CMD install RQuantLib/.
As I said, not very sexy but it works.
A restart of R and Rstudio is necessary.
Hope it helps the next ones and that this will be corrected in future versions.

Resources