Package not found creating conda environment, but can't install it - r

How do I resolve this?
balter#exalab3:~$ conda create -n r322 r=3.2.2
Fetching package metadata .........
Solving package specifications: .
PackageNotFoundError: Package not found: '' Dependency missing in current linux-64 channels:
- r 3.2.2* -> r-base 3.2.2 -> libgcc
Close matches found; did you mean one of these?
libgcc: libgd, libmagic
You can search for packages on anaconda.org with
anaconda search -t conda libgcc
balter#exalab3:~$ conda list | grep libgcc
balter#exalab3:~$ conda install libgcc
Fetching package metadata .........
Solving package specifications: .
PackageNotFoundError: Package not found: '' Package missing in current linux-64 channels:
- libgcc
Close matches found; did you mean one of these?
libgcc: libgd, libmagic
You can search for packages on anaconda.org with
anaconda search -t conda libgcc

Full disclosure, this doesn't directly solve the problem you listed (risking the downvote) but I think this workaround works for what I believe you want to do.
The tricky thing is that the r language is in a different channel. In particular, this looks like the package that you want. Ideally, the conda create command could allow you to specify that channel but it doesn't look like that works. Instead, you can try creating an empty environment -- this seems like the recommended way -- and then do the install in that environment. In other words, you can try this:
conda create -n r322 python
source activate r322
conda install --channel r r=3.3.2

Related

libreadline.so.6 missing - Can not access R via command line after installation

I did put R on path using the .bashrc file. And yet, I do not have access to R through the command line. I have nevertheless no issues with RStudio. When I check for the R location with which R, I get /home/myself/anaconda3/bin/R. I have Ubuntu 20.04. The error message that I get is /home/myself/anaconda3/lib/R/bin/exec/R: error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory. I have version R version 4.1.3 which I have installed recently. Working in JupyterLab in anaconda, I installed again R in a conda environement. Unfortunately, I get inside the conda environment the same error message.
When I try to install the missing package, I get the message:libreadline6 : PreDepends: multiarch-support but it is not installable.
I also tried to install libreadline with conda, conda install -c conda-forge m2-libreadline (as suggested on the anaconda site) as well as conda install -n base -c conda-forge libreadline.so.6. The message I get is: `PackagesNotFoundError: The following packages are not available from current channels:
libreadline.so.6
m2-libreadline`
I will highly appreciate your help. Thanks.

updating packages in older R version with new R version [duplicate]

Andrew Gelman recently lamented the lack of an easy upgrade process for R (probably more relevant on Windows than Linux). Does anyone have a good trick for doing the upgrade, from installing the software to copying all the settings/packages over?
This suggestion was contained in the comments and is what I've been using recently. First you install the new version, then run this in the old verion:
#--run in the old version of R
setwd("C:/Temp/")
packages <- installed.packages()[,"Package"]
save(packages, file="Rpackages")
Followed by this in the new version:
#--run in the new version
setwd("C:/Temp/")
load("Rpackages")
for (p in setdiff(packages, installed.packages()[,"Package"]))
install.packages(p)
Just for completeness, there are some ways to prevent you from having this problem. As Dirk said, save your packages in another directory on your computer.
install.packages("thepackage",lib="/path/to/directory/with/libraries")
You can change the default .Library value using the function .libPaths too
.libPaths("/path/to/directory/with/libraries")
This will put this path as a first value in the .Library variable, and will make it the default.
If you want to automate this further, you can specify this in the Rprofile.site file, which you find in the /etc/ directory of your R build. Then it will load automatically every time R loads, and you don't have to worry about that any more. You can just install and load packages from the specified directory.
Finally, I have some small code included in my Rprofile.site allowing me to reinstall all packages when I install a new R version. You just have to list them up before you update to the new R version. I do that using an .RData file containing an updated list with all packages.
library(utils)
## Check necessary packages
load("G:\Setinfo\R\packagelist.RData") # includes a vector "pkgs"
installed <- pkgs %in% installed.packages()[, 'Package']
if (length(pkgs[!installed]) >=1){
install.packages(pkgs[!installed])
}
I make the packagelist.RData by specifying .Last() in my Rprofile.site. This updates the package list if I installed some :
.Last <- function(){
pkgs <- installed.packages()[,1]
if (length(pkgs) > length(installed)){
save(pkgs,file="G:\Setinfo\R\packagelist.RData")
}
}
When I install a new R version, I just add the necessary elements to the Rprofile.site file and all packages are reinstalled. I have to adjust the Rprofile.site anyway (using sum contrasts, adding the extra code for Tinn-R, these things), so it's not really extra work. It just takes extra time installing all packages anew.
This last bit is equivalent to what is given in the original question as a solution. I just don't need to worry about getting the "installed" list first.
Again, this doesn't work flawless if you have packages that are not installed from CRAN. But this code is easily extendible to include those ones too.
If you are using Windows, you might want to use the installr package:
install.packages("installr")
require(installr)
updateR()
The best way of doing this is from the RGui system. All your packages will be transferred to the new folder and the old ones will be deleted or saved (you can pick either).
Then once you open RStudio again, it immediately recognizes that you are using an updated version. For me this worked like a charm.
More info on installr here.
Two quick suggestions:
Use Gabor's batchfiles which are said to comprise tools helping with e.g. this bulk library relocations. Caveat: I have not used them.
Don't install libraries within the 'filetree' of the installed R version. On Windows, I may put R into C:/opt/R/R-$version but place all libraries into C:/opt/R/library/ using the following snippet as it alleviates the problem in the first place:
$ cat .Renviron # this is using MSys/MinGW which looks like Cygwin
## Example .Renviron on Windows
R_LIBS="C:/opt/R/library"
The method suggested above will not completely work if you have packages that are not from CRAN. For example, a personal package or a package downloaded from a non-CRAN site.
My preferred method on Windows (upgrading 2.10.1 to 2.11.0):
Install R-2.11.0
Copy R-2.10.0/library/* to R-2.11.0/library/
Answer "no" to the prompts asking you if it is okay to overwrite.
Start R 2.11.0
Run the R command update.packages()
With respect to the solution given in the question, it might not be easy to run your older version of R if you have already installed the new version. In this case, you can still reinstall all missing packages from the previous R version as follows.
# Get names of packages in previous R version
old.packages <- list.files("/Library/Frameworks/R.framework/Versions/3.2/Resources/library")
# Install packages in the previous version.
# For each package p in previous version...
for (p in old.packages) {
# ... Only if p is not already installed
if (!(p %in% installed.packages()[,"Package"])) {
# Install p
install.packages(p)
}
}
(Note that the argument to list.files() in the first line of code should be the path to the library directory for your previous R version, where all folders of packages in the previous version are. In my current case, this is "/Library/Frameworks/R.framework/Versions/3.2/Resources/library". This will be different if your previous R version is not 3.2, or if you're on Windows.)
The if statement makes sure that a package is not installed if
It's already installed in the new R version, or
Has been installed as a dependency from a package installed in a previous iteration of the for loop.
Following Dirk's suggestion, here is some R code to do it on windows: How to easily upgrade R on windows XP
Update (15.04.11): I wrote another post on the subject, explaining how to deal with common issues of upgrading R on windows 7
Two options:
Implement my answer here
If you use R under Eclipse with StatET, open Run Configurations, click on Console tab and in the box called R snippet run after startup add this line with your choice of directory: .libPaths("C:/R/library")
I am on Windows 8 and for some weird reason, I can never install packages using my internet connections.
I generally install it using the .zip file from CRAN.
After I went from R 3.2.5 to R 3.3.1.
I simply copied the packages from
C:\Path\to\packa\R\win-library\3.2 to C:\Path\to\packa\R\win-library\3.3.
And then I restarted the R session. Worked perfectly.
I haven't checked if ALL the packages are functioning well.
But, the ones I checked are working perfectly well.
Hope this hack works for everybody.
Cheers.
The accepted answer might work if you have foresight, but I had already gotten rid of the old version so wasn't able to follow these directions.
The steps described below worked for OSX upgrading from 2.1 and 3.1.
UPDATED: To get the directory for your most recent version (instead of typing in 3.1 or 3.2) you can use the below commands. The second one converts directly to the R-variable, skipping . and .. and .DS_Store, use:
OLD=$(ls -d /Library/Frameworks/R.framework/Versions/*.* |tail -n 2 | head -n 1)Resources/library/
echo "packages = c(\"`ls $OLD | tail +4| paste -s -d ',' - | sed -E 's|,|\",\"|'g`\")" | tr -d "/"
(Add |pbcopy to the end to copy it directly to your Mac clipboard)
Then within R you can paste that variable that is generated. Once that is defined in the new version of R, you can loop through the installed packages from the instructions above...
for (p in setdiff(packages, installed.packages()[,"Package"]))
install.packages(p, dependencies=TRUE, quiet=TRUE, ask=FALSE)
for me this page is good
https://www.r-statistics.com/2013/03/updating-r-from-r-on-windows-using-the-installr-package/
or
another option is just install the new option and at final you put, for example in windows in my pc
.libPaths(c(
"D:/Documents/R/win-library/3.2",
"C:/Program Files/R/R-3.2.3/library",
"C:/Program Files/R/R-3.2.0/library",
"D:/Documents/R/win-library/2.15"
)
every path of last version in my case i always put the first path is "D:/Documents/R/win-library/3.2" that is fixed
and then i put the other because you do not need copy or move any packages, in my sugest just call it
linux + bash + debian + apt users:
If you're installing/upgrading to the newest version of R, then we may assume you have root permissions. (Not essential, just makes the process a lot simpler; for consistency the script below uses sudo for all installs.)
As the R packages are also installed by root, it is thus permissible to place these in /usr/local/.
The call to curl below assumes you are already interested in the sid release of R, the very latest unstable version (as required when building/checking an R package) i.e.
cat /etc/apt/sources.list | grep 'sid' || exit 1
although this could easily be replaced with a recent stable release e.g. buster.
Note that I am not using a key as is typically recommended. This is not essential, particularly if (as in the script which follows) we install packages within R itself (Rscript -e below). Also, such keys have a tendency to break/change every few years. Thus, you are of course welcome to add the following preface to the file R.sh which follows:
sudo apt-key adv --keyserver keyserver.ubuntu.com \
--recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
The array of R packages is clearly not exhaustive but gives some examples which I personally find useful. A fresh install/upgrade with the debian package r-recommended, as below, should give the latest version of all of the the standard 'recommended' packages (e.g. survival). I believe there may be a slight lag between a CRAN release and an update to the relevant debian package. Thus, you may wish to add some of these to the array below if having the latest version of a 'recommended' R package is essential.
The debian packages installed in the process below are also neither essential (for using r-base) nor exhaustive but provide a no. of 'add-ons' which are important for a reasonable no. of R packages.
Anyway... place the following in R.sh:
sudo apt update && sudo apt --yes full-upgrade
sudo apt install --yes libappstream4 curl
### ov1 = online version; lv1 = local version (i.e. currently installed)
ov1=$(curl --silent --url https://packages.debian.org/sid/r-base |
grep 'meta name=\"Keywords\"' |
grep --only-matching '[0-9].*[0-9]') ; echo $ov1
## command -v = print a description of COMMAND similar to the `type' builtin
## && = if prior command succeeds, then do; || = if prior fails, then do
command -v 'R --version' &&
lv1=$(R --version |
grep --only-matching '[0-9\.]*[0-9]' |
## || = otherwise
head -1) ||
lv1=0
## 'lt' = less than
if dpkg --compare-versions "$lv1" 'lt' "$ov1"
then ## declare -a = indexed array
declare -a deb1=('r-base' 'r-base-dev' 'r-recommended')
for i in "${deb1[#]}"
do sudo apt install --yes "$i"
done
fi
### certain Debian packages are required by 'R' so best have these first
sudo apt install --yes ccache libcairo2-dev libxml2-dev libcurl4-openssl-dev \
libssl-dev liblapack-dev libssl-dev
declare -a pkg1=('data.table' 'ggplot2' 'knitr' 'devtools' 'roxygen2')
## installing as 'root' so these are installed in
Rscript -e ".libPaths()[1]"
for i in "${pkg1[#]}"
do sudo Rscript -e "install.packages('$i', dependencies=TRUE)"
done
### other useful additions
sudo apt install --yes libblas-dev libboost-dev libarmadillo-dev \
jags pandoc pandoc-citeproc
sudo apt update && sudo apt full-upgrade
Then execute it, e.g. assuming in directory already: source R.sh.
Installing packages (whether debian or R) one-by-one in a loop from shell is somewhat inefficient, but allows for simpler tracing of errors, IMHO. May take some time depending on the no. of R packages, so maybe simplest to let run overnight...
In linux, Now it is very simple. Just make:
install.packages("ropenblas")
ropenblas::rcompiler()

How to force `conda` to install the latest version of `jupyter`?

This question is motivated by `jupyter notebook` gives error: `"Could not open static file ''"` on macOS
After conda update jupyter, jupyter --version gives jupyter-notebook : 6.0.0
However on https://github.com/jupyter/notebook, clicking Branch: master -> tags I see a 6.0.1 tag.
How can I upgrade to 6.0.1?
> conda install jupyter=6.0.1
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- jupyter=6.0.1
Current channels:
- https://repo.anaconda.com/pkgs/main/osx-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
I can't see any candidates on https://anaconda.org
Is this a dead-end?
First, note that the actual package you want to upgrade/install is notebook, not jupyter. The Anaconda channel hasn't released that version of notebook yet. Conda Forge has it, so you can get it with
conda install -c conda-forge notebook
However, just be aware that compatibility between Conda Forge and Anaconda package builds is not guaranteed. Best practice is to create a new env that prioritizes Conda Forge from the start:
conda create -n my_jupyter_env -c conda-forge jupyter
Generally it isn't a good idea to mess with base env, and if you want something other than a default Anaconda install, I recommend starting with Miniconda and leaving base alone (other than the occasional conda upgrade conda).

Errors building R-packages for conda

I am having a tough time installing R-packages that are not available in the Anaconda repositories. My attempts so far can be found here How to install R-packages not in the conda repositories?.
Currently, I am trying to build the R-package rafalib for conda by following the instructions from this article under the heading Building a conda R package.
The first part works fine.
conda skeleton cran rafalib
Out:
Tip: install CacheControl to cache the CRAN metadata
Fetching metadata from http://cran.r-project.org/
Writing recipe for rafalib
Done
The build command runs into errors
conda build r-rafalib
Out:
Removing old build environment
Removing old work directory
BUILD START: r-rafalib-1.0.0-r3.2.2_0
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ......
Solving package specifications: .
Error: Packages missing in current linux-64 channels:
- r 3.2.2*
- r-rcolorbrewer
I have r 3.2.2-64bit installed via conda and it runs without problems. I also already have r-colorbrewer installed via conda and I can use that package without issues in R. Why am I getting these errors when trying to build a conda package?
I am on Linux (Antergos, an Arch derivative) with kernel 4.4.5-1-ARCH.
UPDATE 2015/04/19
Thanks to this answer, I found out that I could include the dependencies by building them separately in the same directory as the package I want to install. That didn't work for me, but I also read that I can include a channel in the build command with -c, just as when installing. So now I do:
conda build -c r r-rafalib
This gets passed all the dependency problems, but after fetching, extracting and linking packages, it fails. Here is the end of the error message.
Removing old work directory
Source cache directory is: /home/joel/anaconda2/conda-bld/src_cache
Downloading source to cache: rafalib_1.0.0.tar.gz
Downloading http://cran.r-project.org/src/contrib/rafalib_1.0.0.tar.gz
rafalib_1.0.0. 100% |#######################| Time: 0:00:00 4.87 MB/s
Success
Extracting download
Package: r-rafalib-1.0.0-r3.2.2_0
source tree in: /home/joel/anaconda2/conda-bld/work/rafalib
+ mv DESCRIPTION DESCRIPTION.old
+ grep -v '^Priority: ' DESCRIPTION.old
+ /home/joel/anaconda2/envs/_build/bin/R CMD INSTALL --build .
sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook
Command failed: /bin/bash -x -e /home/joel/drafts/r-rafalib/build.sh
The error sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook is the same as I encounter when using install.packages() as reported here.
There is some related discussion in this thread. I have tried to get around this error by installing different versions of ncurses, including this patched version, and I have tried to link the readline libraries, as suggested here, but I keep running into the same error. I'm quite lost at this point and any help to solve this would be greatly appreciated.
Although I started out with a different problem, the final solution turned out to be the same as I posted elsewhere How to install R-packages not in the conda repositories?. I am adding it here for completeness.
In the end, I got around the rl_event_hookproblems by following the approach recommended here and symlinking anaconda's libreadline to the system one:
mv ~/anaconda3/lib/libreadline.s.6.2 ~/anaconda3/lib/libreadline.s.6.2.bak
ln -s /usr/lib/libreadline.so.6.3 ~/anaconda3/lib/libreadline.s.6.2
I am still having troubles installing some dependency heavy R-packages due to failure to load shared objects when using install.packages() from withing R. However, simpler packages work fine and I can get most of the dependency heavy packages from anacondas R-repositories.

Painless way to install a new version of R?

Andrew Gelman recently lamented the lack of an easy upgrade process for R (probably more relevant on Windows than Linux). Does anyone have a good trick for doing the upgrade, from installing the software to copying all the settings/packages over?
This suggestion was contained in the comments and is what I've been using recently. First you install the new version, then run this in the old verion:
#--run in the old version of R
setwd("C:/Temp/")
packages <- installed.packages()[,"Package"]
save(packages, file="Rpackages")
Followed by this in the new version:
#--run in the new version
setwd("C:/Temp/")
load("Rpackages")
for (p in setdiff(packages, installed.packages()[,"Package"]))
install.packages(p)
Just for completeness, there are some ways to prevent you from having this problem. As Dirk said, save your packages in another directory on your computer.
install.packages("thepackage",lib="/path/to/directory/with/libraries")
You can change the default .Library value using the function .libPaths too
.libPaths("/path/to/directory/with/libraries")
This will put this path as a first value in the .Library variable, and will make it the default.
If you want to automate this further, you can specify this in the Rprofile.site file, which you find in the /etc/ directory of your R build. Then it will load automatically every time R loads, and you don't have to worry about that any more. You can just install and load packages from the specified directory.
Finally, I have some small code included in my Rprofile.site allowing me to reinstall all packages when I install a new R version. You just have to list them up before you update to the new R version. I do that using an .RData file containing an updated list with all packages.
library(utils)
## Check necessary packages
load("G:\Setinfo\R\packagelist.RData") # includes a vector "pkgs"
installed <- pkgs %in% installed.packages()[, 'Package']
if (length(pkgs[!installed]) >=1){
install.packages(pkgs[!installed])
}
I make the packagelist.RData by specifying .Last() in my Rprofile.site. This updates the package list if I installed some :
.Last <- function(){
pkgs <- installed.packages()[,1]
if (length(pkgs) > length(installed)){
save(pkgs,file="G:\Setinfo\R\packagelist.RData")
}
}
When I install a new R version, I just add the necessary elements to the Rprofile.site file and all packages are reinstalled. I have to adjust the Rprofile.site anyway (using sum contrasts, adding the extra code for Tinn-R, these things), so it's not really extra work. It just takes extra time installing all packages anew.
This last bit is equivalent to what is given in the original question as a solution. I just don't need to worry about getting the "installed" list first.
Again, this doesn't work flawless if you have packages that are not installed from CRAN. But this code is easily extendible to include those ones too.
If you are using Windows, you might want to use the installr package:
install.packages("installr")
require(installr)
updateR()
The best way of doing this is from the RGui system. All your packages will be transferred to the new folder and the old ones will be deleted or saved (you can pick either).
Then once you open RStudio again, it immediately recognizes that you are using an updated version. For me this worked like a charm.
More info on installr here.
Two quick suggestions:
Use Gabor's batchfiles which are said to comprise tools helping with e.g. this bulk library relocations. Caveat: I have not used them.
Don't install libraries within the 'filetree' of the installed R version. On Windows, I may put R into C:/opt/R/R-$version but place all libraries into C:/opt/R/library/ using the following snippet as it alleviates the problem in the first place:
$ cat .Renviron # this is using MSys/MinGW which looks like Cygwin
## Example .Renviron on Windows
R_LIBS="C:/opt/R/library"
The method suggested above will not completely work if you have packages that are not from CRAN. For example, a personal package or a package downloaded from a non-CRAN site.
My preferred method on Windows (upgrading 2.10.1 to 2.11.0):
Install R-2.11.0
Copy R-2.10.0/library/* to R-2.11.0/library/
Answer "no" to the prompts asking you if it is okay to overwrite.
Start R 2.11.0
Run the R command update.packages()
With respect to the solution given in the question, it might not be easy to run your older version of R if you have already installed the new version. In this case, you can still reinstall all missing packages from the previous R version as follows.
# Get names of packages in previous R version
old.packages <- list.files("/Library/Frameworks/R.framework/Versions/3.2/Resources/library")
# Install packages in the previous version.
# For each package p in previous version...
for (p in old.packages) {
# ... Only if p is not already installed
if (!(p %in% installed.packages()[,"Package"])) {
# Install p
install.packages(p)
}
}
(Note that the argument to list.files() in the first line of code should be the path to the library directory for your previous R version, where all folders of packages in the previous version are. In my current case, this is "/Library/Frameworks/R.framework/Versions/3.2/Resources/library". This will be different if your previous R version is not 3.2, or if you're on Windows.)
The if statement makes sure that a package is not installed if
It's already installed in the new R version, or
Has been installed as a dependency from a package installed in a previous iteration of the for loop.
Following Dirk's suggestion, here is some R code to do it on windows: How to easily upgrade R on windows XP
Update (15.04.11): I wrote another post on the subject, explaining how to deal with common issues of upgrading R on windows 7
Two options:
Implement my answer here
If you use R under Eclipse with StatET, open Run Configurations, click on Console tab and in the box called R snippet run after startup add this line with your choice of directory: .libPaths("C:/R/library")
I am on Windows 8 and for some weird reason, I can never install packages using my internet connections.
I generally install it using the .zip file from CRAN.
After I went from R 3.2.5 to R 3.3.1.
I simply copied the packages from
C:\Path\to\packa\R\win-library\3.2 to C:\Path\to\packa\R\win-library\3.3.
And then I restarted the R session. Worked perfectly.
I haven't checked if ALL the packages are functioning well.
But, the ones I checked are working perfectly well.
Hope this hack works for everybody.
Cheers.
The accepted answer might work if you have foresight, but I had already gotten rid of the old version so wasn't able to follow these directions.
The steps described below worked for OSX upgrading from 2.1 and 3.1.
UPDATED: To get the directory for your most recent version (instead of typing in 3.1 or 3.2) you can use the below commands. The second one converts directly to the R-variable, skipping . and .. and .DS_Store, use:
OLD=$(ls -d /Library/Frameworks/R.framework/Versions/*.* |tail -n 2 | head -n 1)Resources/library/
echo "packages = c(\"`ls $OLD | tail +4| paste -s -d ',' - | sed -E 's|,|\",\"|'g`\")" | tr -d "/"
(Add |pbcopy to the end to copy it directly to your Mac clipboard)
Then within R you can paste that variable that is generated. Once that is defined in the new version of R, you can loop through the installed packages from the instructions above...
for (p in setdiff(packages, installed.packages()[,"Package"]))
install.packages(p, dependencies=TRUE, quiet=TRUE, ask=FALSE)
for me this page is good
https://www.r-statistics.com/2013/03/updating-r-from-r-on-windows-using-the-installr-package/
or
another option is just install the new option and at final you put, for example in windows in my pc
.libPaths(c(
"D:/Documents/R/win-library/3.2",
"C:/Program Files/R/R-3.2.3/library",
"C:/Program Files/R/R-3.2.0/library",
"D:/Documents/R/win-library/2.15"
)
every path of last version in my case i always put the first path is "D:/Documents/R/win-library/3.2" that is fixed
and then i put the other because you do not need copy or move any packages, in my sugest just call it
linux + bash + debian + apt users:
If you're installing/upgrading to the newest version of R, then we may assume you have root permissions. (Not essential, just makes the process a lot simpler; for consistency the script below uses sudo for all installs.)
As the R packages are also installed by root, it is thus permissible to place these in /usr/local/.
The call to curl below assumes you are already interested in the sid release of R, the very latest unstable version (as required when building/checking an R package) i.e.
cat /etc/apt/sources.list | grep 'sid' || exit 1
although this could easily be replaced with a recent stable release e.g. buster.
Note that I am not using a key as is typically recommended. This is not essential, particularly if (as in the script which follows) we install packages within R itself (Rscript -e below). Also, such keys have a tendency to break/change every few years. Thus, you are of course welcome to add the following preface to the file R.sh which follows:
sudo apt-key adv --keyserver keyserver.ubuntu.com \
--recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
The array of R packages is clearly not exhaustive but gives some examples which I personally find useful. A fresh install/upgrade with the debian package r-recommended, as below, should give the latest version of all of the the standard 'recommended' packages (e.g. survival). I believe there may be a slight lag between a CRAN release and an update to the relevant debian package. Thus, you may wish to add some of these to the array below if having the latest version of a 'recommended' R package is essential.
The debian packages installed in the process below are also neither essential (for using r-base) nor exhaustive but provide a no. of 'add-ons' which are important for a reasonable no. of R packages.
Anyway... place the following in R.sh:
sudo apt update && sudo apt --yes full-upgrade
sudo apt install --yes libappstream4 curl
### ov1 = online version; lv1 = local version (i.e. currently installed)
ov1=$(curl --silent --url https://packages.debian.org/sid/r-base |
grep 'meta name=\"Keywords\"' |
grep --only-matching '[0-9].*[0-9]') ; echo $ov1
## command -v = print a description of COMMAND similar to the `type' builtin
## && = if prior command succeeds, then do; || = if prior fails, then do
command -v 'R --version' &&
lv1=$(R --version |
grep --only-matching '[0-9\.]*[0-9]' |
## || = otherwise
head -1) ||
lv1=0
## 'lt' = less than
if dpkg --compare-versions "$lv1" 'lt' "$ov1"
then ## declare -a = indexed array
declare -a deb1=('r-base' 'r-base-dev' 'r-recommended')
for i in "${deb1[#]}"
do sudo apt install --yes "$i"
done
fi
### certain Debian packages are required by 'R' so best have these first
sudo apt install --yes ccache libcairo2-dev libxml2-dev libcurl4-openssl-dev \
libssl-dev liblapack-dev libssl-dev
declare -a pkg1=('data.table' 'ggplot2' 'knitr' 'devtools' 'roxygen2')
## installing as 'root' so these are installed in
Rscript -e ".libPaths()[1]"
for i in "${pkg1[#]}"
do sudo Rscript -e "install.packages('$i', dependencies=TRUE)"
done
### other useful additions
sudo apt install --yes libblas-dev libboost-dev libarmadillo-dev \
jags pandoc pandoc-citeproc
sudo apt update && sudo apt full-upgrade
Then execute it, e.g. assuming in directory already: source R.sh.
Installing packages (whether debian or R) one-by-one in a loop from shell is somewhat inefficient, but allows for simpler tracing of errors, IMHO. May take some time depending on the no. of R packages, so maybe simplest to let run overnight...
In linux, Now it is very simple. Just make:
install.packages("ropenblas")
ropenblas::rcompiler()

Resources