2

When I try to install certain packages (imputeTS) that need libRblas.so which AFAIK refers to OpenBLAS I get an error that it was not found:

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/home/jay/R/x86_64-pc-linux-gnu-library/4.2/fracdiff/libs/fracdiff.so':
  libRblas.so: cannot open shared object file: No such file or directory
Calls: <Anonymous> ... asNamespace -> loadNamespace -> library.dynam -> dyn.load
Execution halted

However, the sessionInfo() indicates, that R actually finds it.

> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

I learned from this thread that "maybe ... another version of R [was built] and it sits in ... [the] $PATH before the packaged version", which is likely to be the case; my former R version 4.2.0 was a self-compiled one, and I removed it by downloading the source again and ./configure - make uninstall. This one is installed via sudo apt install r-base-core, though. Probably now there is a mess somewhere. Unfortunately the cited thread was solved differently, and I'm looking now for the respective conclusion.

Here is some more information:

whereis R gives

~$ whereis R
R: /usr/bin/R /usr/lib/R /usr/lib64/R /etc/R /usr/local/lib/R /usr/share/R /usr/share/man/man1/R.1.gz

From the respective files from the error message, using sudo find ~ -name '<file>', fracdiff.so was found, whereas libRblas.so wasn't.

~/R/x86_64-pc-linux-gnu-library/4.2/fracdiff/libs/fracdiff.so

I already tried,

~$ sudo apt install libopenblas-dev

but obviously it is installed.

libopenblas-dev is already the newest version (0.3.20+ds-1).

Following the suggestions of this, libRlapack.so and libRblas.so obviously don't exist on my system, and the other suggestion just gives:

~$ sudo update-alternatives --config libblas.so
update-alternatives: error: no alternatives for libblas.so
jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • 1
    Note that the first error message is from `fracdiff`. Consider inspecting / rebuilding that package. – Dirk Eddelbuettel Jul 13 '22 at 13:35
  • 1
    Yes, @jay.sf the error message you posted seems to be related to the package fracdiff. Which is a dependency of a dependency from imputeTS ( imputeTS imports forecast, which imports fracdiff). So when you install imputeTS, these package will also be installed. Could you try installing just fracdiff? This would help assessing if your issue has anything to do with imputeTS itself or if the actual problem only emerges from the dependency. – Steffen Moritz Jul 14 '22 at 01:17
  • Thanks for the hints guys, so my assumption of a hopeless mess was correct. See my [answer](https://stackoverflow.com/a/72978650/6574038) below. – jay.sf Jul 14 '22 at 10:11

2 Answers2

2

There should never be a "requirement" for libRblas.so. In short, R allows you to build with the BLAS and LAPACK (subset of) sources it shipts, you then get this libRblas.so. Or you can use the system BLAS and LAPACK libraries, which the Debian (and hence Ubuntu) package I am responsible for has been doing for probably close to twenty years, and which allows you to switch BLAS installation (Atlas, OpenBLAS, MKL, back in the day also Goto, ...).

As a demonstration, I just launched a suitable Ubuntu 22.04 Docker container based on r2u as it combines having R pre-made (using my r-base-core package with the external BLAS linkage) as well as the (awesome !!) ability to take all of CRAN as Ubuntu binaries (see r2u for more). In short:

edd@rob:~$ docker run --rm -ti --security-opt seccomp=unconfined eddelbuettel/r2u:jammy                                                                                                                            
root@818091e49861:/# export PS1="root@r2u_docker:\w# "                                                                                                                                                             
root@r2u_docker:/# echo "192.168.1.114 dirk.eddelbuettel.com" >> /etc/hosts                                                                                                                                        
root@r2u_docker:/# install.r imputeTS              ## one command !!                                                                                                                                                                
Install system packages as root...                                                                                                                                                                                 
Reading package lists... Done                                                                                                                                                                                      
Building dependency tree... Done                                                                                                                                                                                   
Reading state information... Done                                                                                                                                                                                  
Ign https://dirk.eddelbuettel.com/cranapt jammy InRelease                                                                                                                                                         
Hit https://dirk.eddelbuettel.com/cranapt jammy Release                                                                                                                                                           
Hit http://archive.ubuntu.com/ubuntu jammy InRelease                                                                                                                                                              
Hit http://archive.ubuntu.com/ubuntu jammy-updates InRelease                                                                                                                                                      
Hit http://archive.ubuntu.com/ubuntu jammy-backports InRelease                                                                                                                                                    
Hit http://security.ubuntu.com/ubuntu jammy-security InRelease                                                                                                                                                     
Get:1 https://ppa.launchpadcontent.net/marutter/rrutter4.0/ubuntu jammy InRelease [17.5 kB]                                                                                                                        
Fetched 17.5 kB in 0s (0 B/s)                                                                                                                                                                                     
Reading package lists... Done                                                                                                                                                                                      
Building dependency tree... Done                                                                                                                                                                                   
Reading state information... Done                                                                                                                                                                                  
Get:1 https://dirk.eddelbuettel.com/cranapt jammy/main amd64 r-cran-bitops amd64 1.0-7-1.ca2204.1 [25.5 kB]                                                                                                       
Get:2 https://dirk.eddelbuettel.com/cranapt jammy/main amd64 r-cran-glue amd64 1.6.2-1.ca2204.1 [143 kB]                                                                                                           
[... cutting here to satisfy SO quote limit ...]
Setting up r-cran-forecast (8.16-1.ca2204.1) ...
Setting up r-cran-imputets (3.2-1.ca2204.1) ...
root@r2u_docker:/# 

after which we can indeed launch R and load it just fine:

root@r2u_docker:/# R

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(imputeTS)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
> 

It uses external BLAS/LAPACK "by design":

root@r2u_docker:/# dpkg -l | grep -i "blas\|lapack" | cut -c-90
ii  libblas-dev:amd64            3.10.0-2ubuntu1                         amd64        Basi
ii  libblas3:amd64               3.10.0-2ubuntu1                         amd64        Basi
ii  liblapack-dev:amd64          3.10.0-2ubuntu1                         amd64        Libr
ii  liblapack3:amd64             3.10.0-2ubuntu1                         amd64        Libr
root@r2u_docker:/# 

So I think this may be self-imposed by a combination of you having maybe compiled R locally plus the imputeTS not dealing well with that (it should, it may be a bug). But I hope this also shows that this can be so much easier too.

If you have more detailed follow-up questions please come to the r-sig-debian list which is friendly, no-sensense and low-volume.

PS For completness, the container's sessionInfo() in a fresh session:

> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.1 bspm_0.3.9    
> 

PPS A 'live' demo in one animated gif is in this tweet (tweeted as one cannot attach gifs over 2mb here).

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Nice of you to stop by this question. From our [previous discussion](https://stackoverflow.com/q/72115826/6574038) I learned that installing a regularly `apt` should be preferred if it is available, which is exactly what I did this time (I just updated that information in my question since it probably wasn't clear enough). The weird thing is, in my locally compiled version I did not have that issue:) Regarding your answer, I'm not sure how to use it; it proposes a presumably great other type of setup but won't install/fix any of BLAS/LAPACK/package on my system. Plz correct me if I'm wrong. – jay.sf Jul 13 '22 at 13:25
  • There are a few questions glued together in this paragraph I do not have time to disentangle now. I can only encourage you to stop by the r-sig-debian list for follow-up as I suggested. You will get an unbiased discussion of c2d4u, r2u and other tricks. In short, imputeTS will also install cleanly from source on a proper system (or else CRAN would yell at it) so the errors are likely all on your end. Sorry for the likely bad news. We can help. – Dirk Eddelbuettel Jul 13 '22 at 13:34
0

Some comments have put me on the right track and helped me to solve the problem—I will briefly summarize.

Since a dependencies issue was suspected, I installed the package from which the error message originated (fracdiff in this case) and tried again to install the target package. The error reoccurred, but came from a different package indicating cascading problems. Weirdly enough, I definitely knew the package was installed, so I felt my initial suspicion confirmed, that I might have made a mess with the libs folders when updating R as described in the OP.

Since I could assume that this would happen again and again, the conclusion was to uninstall R completely, and this time the packages as well, and then reinstall everything. Now I could install the target package among others without any problems.

Fortunately, this is quite easy on Linux. Also all packages can be reinstalled relatively unattended. The how-to's are spread out over several threads and sites, I'll put the strings together, adding the references.

Here is what I did in R and in Bash (you will need su/sudo):

  1. Store packages (in R) 1
tmp <- installed.packages()
installedpkgs <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
saveRDS(installedpkgs, 'installed_old.rds')
  1. Remove R completely 2
dpkg -l | grep ^ii | awk '$2 ~ /^r-/ { print $2 }' | sudo xargs apt-get remove --purge -y
  1. Remove all R packages 3

The locations might differ from yours.

R -e '.libPaths()'
rm -rf /home/jay/R/x86_64-pc-linux-gnu-library/4.2 /usr/local/lib/R/site-library /usr/lib/R/site-library /usr/lib/R/library
  1. Install R (here with apt) 4
apt install r-base-core
  1. Restore R packages 5

This runs for a while. Note that only packages that can be found in repositories are installed.

installedpkgs <- readRDS("installed_old.rds")
tmp <- installed.packages()
installedpkgs.new <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
missing <- setdiff(installedpkgs, installedpkgs.new)
install.packages(missing)
update.packages(ask=FALSE)
jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • "This runs for a while." Take a look at [r2u](https://eddelbuettel.github.io/r2u/) which can even try in your browser via gitpod. I demoed this for various packages -- complete _and error-free thanks to apt_ binary installation in _seconds_. – Dirk Eddelbuettel Jul 14 '22 at 19:52
  • @DirkEddelbuettel I appreciate your effort in r2u very much. Regardless, this answer will be a welcome remedy for victims of a messed up system caused by a clumsy switch from locally compiled R to apt-packaged R. – jay.sf Jul 14 '22 at 20:06
  • We are all adults, and you are free to spend your time as you see fit. I just felt the fairly absolute dictum of "this will take a while" needs the qualifier "if you insist on installing from source, or mostly from source". To each their own -- I also built (mostly) from source for 25 years on my main box, but switched eg all CI use to premade binaries where I could. Now with r2u it covers all of CRAN which makes a few users, myself included, quite happy. But it's a big tent and everybody can do as they please. – Dirk Eddelbuettel Jul 14 '22 at 20:15