mboeck11 / BGVAR

Toolbox for the estimation of Bayesian Global Vector Autoregressions in R.
27 stars 20 forks source link

Trouble installing package on linux #10

Open jrschwartz opened 2 years ago

jrschwartz commented 2 years ago

I am trying to install the BGVAR package on linux - specifically AWS Linux 2 Here is the log - not the "Loading profile..." that got inserted into the final g++ line and is breaking the compilation

install.packages("BGVAR",dep=TRUE) Installing package into '/home/ec2-user/R/x86_64-koji-linux-gnu-library/4.0' (as 'lib' is unspecified) trying URL 'https://repo.miserver.it.umich.edu/cran/src/contrib/BGVAR_2.4.3.tar.gz ' Content type 'application/octet-stream' length 3192687 bytes (3.0 MB)

downloaded 3.0 MB

Loading profile...

The downloaded source packages are in '/tmp/RtmpVmWV7V/downloaded_packages'

mboeck11 commented 2 years ago

Do you have installed the compiler g++ on Linux?

jrschwartz commented 2 years ago

Yes, g++ is installed [ec2-user@ip-XXX]$ g++ --version g++ (GCC) 7.3.1 20180712 (Red Hat 7.3.1-13) Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you look at the log, you will see "Loading profile" in the compile line this appears to be the problem

g++ -m64 -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-z,relro -o BGVAR.so BVAR_linear.o RcppExports.o do_rgig1.o gvar_stacking.o helper.o irf.o -L/usr/lib64/R/lib -lRlapack -L/usr/lib64/R/lib -lRblas -lgfortran -lm -lquadmath Loading profile... -L/usr/lib64/R/lib -lR

is that a variable that has been improperly set?

mboeck11 commented 2 years ago

That's odd, because this is not something I specify from the BGVAR side.

jrschwartz commented 2 years ago

Have you ever installed this on an AWS ec2 linux machine?

mboeck11 commented 2 years ago

No, personally I've checked the package only on Windows and Mac machines. Insofar, I am unfortunately only of little help for Linux. But I am happy to help if I can do anything from the BGVAR side.

jrschwartz commented 2 years ago

I will see if AWS support can help Thank you

jrschwartz commented 2 years ago

I found the issue: Your Makevars: CXX_STD = CXX11 PKG_CPPFLAGS = -I../inst/include/ -DARMA_NO_DEBUG PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::RcppParallelLibs()")

On my system, [ec2-user@ip-XXX etc]$ ${R_HOME}/bin/Rscript -e "RcppParallel::RcppParallelLibs()" Loading profile...

What should that be? How can I change it?

jrschwartz commented 2 years ago

OK, so I think I figured this out https://www.rdocumentation.org/packages/RcppParallel/versions/4.3.4/topics/RcppParallelLibs "This function is typically called from Makevars.win as follows" I downloaded the source, took out the last line from your Makevars, installed from local source and it succeeded

I now have a code error that doesn't occur in windows, only linux

traceback() 8: stop(structure(list(message = "Object was created without names.", call = gvar_stacking(xglobal = xglobal, plag = as.integer(plag), globalpost = globalpost, draws = as.integer(draws), thin = as.integer(thin), trend = trend, eigen = TRUE, verbose = verbose), cppstack = NULL), class = c("Rcpp::index_out_of_bounds", "C++Error", "error", "condition"))) 7: gvar_stacking(xglobal = xglobal, plag = as.integer(plag), globalpost = globalpost, draws = as.integer(draws), thin = as.integer(thin), trend = trend, eigen = TRUE, verbose = verbose) 6: .gvar.stacking.wrapper(xglobal = xglobal, plag = plag, globalpost = globalpost, draws = draws, thin = thin, trend = trend, eigen = eigen, trim = trim, verbose = verbose) 5: bgvar(Data = list.data, W = W.trade0012.adj, draws = 5000, burnin = 15000, plag = 4, prior = "SSVS", hyperpara = NULL, SV = TRUE, thin = 10, Ex = NULL, trend = FALSE, expert = list(save.shrink.store = TRUE, cores = 6), hold.out = 0, eigen = 1, verbose = TRUE) at bond.2021.rstar.boot.one.r#79 4: eval(ei, envir) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source("bond.2021.rstar.boot.one.r")

Is there an underlying library outside of R that needs to be installed?

mboeck11 commented 2 years ago

Yes, there are several packages on which BGVAR relies. In particular, have you installed Rcpp and RcppArmadillo?

Thr makevars files usually define which exact C++ should be used. Maybe some of those are not available/installed on Linux?

jrschwartz commented 2 years ago

Both of those libraries have been installed

SriN-Berunda commented 2 years ago

Both of those libraries have been installed

I had the same issue today with two R packages: BGVAR and rmgarch. I discovered that this is due to ${R_HOME}/bin/Rscript -e "RcppParallel::RcppParallelLibs()" variable being not evaluated to something other than NULL. This variable is being set in the .Rprofile file such as .first and .last variables when every R child process is launched. I suspect your .first says "Loading Profile" in your .Rprofile.

To circumvent this, simply comment out anything that is being loaded in your .Rprofile or .Renvironment files and try to install the packages again.

grantmcdermott commented 1 year ago

tl;dr Install the rspm package and then add suppressMessages(rspm::enable()) to your ~/.Rprofile file. Restart your R session and you should be able to install BGVAR without any issues.

Details:

Instead of configuring your Makevars and compiling everything yourself, a much simpler solution is to simply install a precompiled version for your Linux distro. The good folks at Posit (nee RStudio) provide R package binaries for a bunch of different distros via their Public Package Manager.

In the specific case of AL2, this is essentially a close derivative of CentOS 7, so you just need to amend the default repo mirror accordingly: install.packages("BGVAR", repos = c("PPM" = "https://packagemanager.rstudio.com/all/__linux__/centos7")).

A better solution is to add options(repos = c("PPM" = "https://packagemanager.rstudio.com/all/__linux__/centos7")) to your ~/.Rprofile so that packages are automatically installed from this mirror instead of one of the usual CRAN ones... But an even better solution is to let the rspm package handle all of this stuff for you, since it will (a) automatically figure out which PPM mirror you need and (b) resolve any additional system dependencies at the same time. This is the tl;dr tip at the top of my reply. I've just tested it by installing BGVAR on an AL2 instance and it works perfectly.