I compiled R from source and it doesn't find certificates - r

I am deploying multiple R versions on multiple virtual desktops. I've built 3.6.3 and 4.1.2 R from source on Ubuntu 18.04.3 LTS. None of them finds the system-wide Rprofile.site file in /etc/R or the system certificates in /usr/share/ca-certificates. However R (3.4.4) installed with APT has no such problems. I used Ansible, but for the sake of this question I reproduced the deployment for one host with a shell script.
#!/bin/bash
set -euo pipefail
# install build dependecies
(command -v apt && apt-get build-dep r-base) || (command -v dnf && dnf builddep R)
version='4.1.2'
major_version=$(echo "$version" | cut -c 1)
wget "https://cran.rstudio.com/src/base/R-$major_version/R-$version.tar.gz"
tar -xzf R-$version.tar.gz
cd R-$version
./configure \
--prefix=/opt/R/$version \
--sysconfdir=/etc/R \
--enable-R-shlib \
--with-pcre1 \
--with-blas \
--with-lapack
make -j 8
make install
Note: It should run on most Linux distros with APT or RPM package managers. Increase the -j argument of make, if you have the enough cores, but no time.
So I defined the installation prefix as /opt/R/$version , but I want it read config files from /etc/R (defined --sysconfdir=/etc/R). However when I open the R interactive shell (/opt/R/4.1.2/bin/R) to try install a package:
install.packages("remotes")
then I will be prompted to choose a R package mirror, but one already defined in /etc/R/Rprofile.site:
local({
r <- getOption("repos")
r["CRAN"] <- "https://cloud.r-project.org"
options(repos = r)
})
I can force the R shell to find the Rprofile.site file by defining it with the R_PROFILE environment variable.
export R_PROFILE=/etc/R/Rprofile.site
/opt/R/4.1.2/bin/R
then call install.packages("remotes") again in the R shell. Now no mirror selection prompt will be shown, but the following error:
Warning: unable to access index for repository https://cloud.r-project.org/src/contrib:
cannot open URL 'https://cloud.r-project.org/src/contrib/PACKAGES'
Warning message:
package ‘remotes’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
So it cannot access the repository index (real problem), then concludes that the package ‘remotes’ package is not available for my R version. Which is BS, since it was not able to read the index at the first place. So I tried a simple HTTP call in the same R shell.
curlGetHeaders("https://example.com")
and got this error:
Error in curlGetHeaders("https://example.com") : libcurl error code 77:
unable to access SSL/TLS CA certificates
So it cannot find the CA certificates in /usr/share/ca-certificates.
Since the R installed by APT has none of these problems. The compiled R does not search the right places. Even if I omit the --sysconfdir=/etc/R build option and copy or symlink the /etc/R directory under the prefix, so it will be at /opt/R/4.1.2/etc. It will still not find its config files.
The greater problem that I do not even no know how to specify the /usr/share so it may find the certificates. The rsharedir build options (the -- also missing in the makefile) will not do, because it should point to /usr/share/R/ not /usr/share, which would be a bad practice anyway.
I also tried all of this it with the 3.6.3 R version and got the same results.
Questions: How can I make the compiled R installations to find the system-wide or any config files and the certificates.
Update 1
I ran the build script on a Ubuntu server which I do not manage with the same Ansible code. On both of them R successfully finds the certificates. So the problem is not with the build script but the system state.
Update 2
I created a simple R script (install-r-package.R) which install a package:
install.packages("renv", repos="https://cran.wu.ac.at/")
then I executed it with Rscript and traced which file do they open on both the correct and erroneous hosts:
strace -o strace.log -e trace=open,openat,close,read,write,connect,accept ./Rscript install-r-package.R
It turned out that on the problematic system R does not even try to open the certificate files.
The relevant trace snippet on the correct system:
connect(5, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("137.208.57.37")}, 16) = -1 EINPROGRESS (Operation now in progress)
openat(AT_FDCWD, "/etc/ssl/certs/ca-certificates.crt", O_RDONLY) = 6
read(6, "-----BEGIN CERTIFICATE-----\nMIIH"..., 200704) = 200704
read(6, "--\n", 4096) = 3
read(6, "", 4096) = 0
close(6) = 0
on the problematic system:
connect(5, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("137.208.57.37")}, 16) = -1 EINPROGRESS (Operation now in progress)
openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/nss/libsoftokn3.so", O_RDONLY|O_CLOEXEC) = 6
read(6, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220A\0\0\0\0\0\0"..., 832) = 832
close(6) = 0
In both cases R connects to the mirror (137.208.57.37) after that on the correct system it reads the ca-certificates.crt certificate file and many other .crt files after that. However the erroneous system jump this step altogether.

Finally I found the solution:
Since both system has the arch and OS. I cross copied the R compiled installations between them. The R which was compiled on the problematic system, but was run on the correct one gave the warnings below after the calling of the install.packages("renv", repos="https://cran.wu.ac.at/")
Warning: unable to access index for repository https://cran.wu.ac.at/src/contrib:
internet routines cannot be loaded
Warning messages:
1: In download.file(url, destfile = f, quiet = TRUE) :
unable to load shared object '/opt/R/4.1.2/lib/R/modules//internet.so':
libcurl-nss.so.4: cannot open shared object file: No such file or directory
2: package ‘remotes’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
If I do the reverse then the installation works.
The libcurl-nss.so.4: cannot open shared object file: No such file or directory line gave me the clue that different libcurl4 flavors was used as build dependecies. I checked which dev dependecies were installed on the systems and libcurl4-nss-dev 7.58.0-2ubuntu3 were installed on the problematic system and libcurl4-gnutls-dev 7.58.0-2ubuntu3.16 on the correct system.
So I purged libcurl4-gnutls-dev from the problematic system:
apt purge libcurl4-nss-dev -y
and installed libcurl4-gnutls-dev:
aptitude install libcurl4-gnutls-dev
I used aptitude, because I had to downgrade libcurl3-gnutls 7.58.0-2ubuntu3.16 (now) -> 7.58.0-2ubuntu3 (bionic) which is a dependency of libcurl4-gnutls-dev, then I run a make clean in the R-4.1.2 source directory. Finally I re-run the build script from the question, and got a well working R, which can read the certificates, hence can reach the HTTPS using package mirrors.

Related

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()

Rstudio does not start "Unable to determine real path of R script" due to previous error during compilation of R

I am using Fedora 32, I have R (3.5.1 ) within conda. I also compiled R 4.0.0 from source but since I was having another problem with Rstudio I removed this version trying to solve these issues. (With 4.0.0 I couldn't install packages because I got an 'C++11 standard requested but CXX11 is not defined' error, I made the mistake of using --with-x=no during that compiling)
Now I tried to either compile a new version (4.0.1) or get R through yum, but every time I try to reinstall Rstudio I get this error:
Unable to determine real path of R script /home/andrespara/R-4.0.0/bin/R (system error 2 (Folder doesn'exist*))
I removed ~/.config/rstudio ~/.local/share/rstudio ~/.rstudio/ every time I removed/reinstalled Rstudio. I also searched for help in the rstudio community forums. I also
I compiled 4.0.1 with this line (deactivating conda before this avoided the X11 error that I had before)
./configure \
--prefix=/opt/R/${R_VERSION} \
--enable-memory-profiling \
--enable-R-shlib \
--with-blas \
--with-lapack
I added symbolic links following these instructions https://docs.rstudio.com/resources/install-r-source/
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
R 4.0.1 is now correctly installed, I even used it today and installed some package the only missing link is with Rstudio and its installation that doesn't recognize it.
My question is how to either jump to another version of R working with Rstudio and get rid of that message when Rstudio starts.
I should add can't even start Rstudio because it still asks for the 'broken version' even when I tried to reinstall it several times.
I managed to solve this thanks to a colleague who found a workaround.
First running RSTUDIO_WHICH_R=$(which R) and then rstudio in the console bypassed the first error.
conda deactivate
RSTUDIO_WHICH_R=$(which R)
rstudio
Then knowing the launcher was the error and thanks to this answer https://askubuntu.com/a/112259/265501 I went to /usr/share/applications
and edited the line pointing to the useless binary with the correct one in the rstudio.desktop file found there.
Edit the file ~/.profile
export RSTUDIO_WHICH_R=$(which R)
The problem is that you've created a symlink from the wrong location. Rstudio launcher is looking for R in /home/andrespara/R-4.0.0/bin/R but it can't find it there. Your symlinks should be redirecting from that location to where you installed R like this:
sudo ln -s /opt/R/${R_VERSION}/bin/R home/andrespara/R-4.0.0/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript home/andrespara/R-4.0.0/bin/Rscript
If any of the directories in that file path don't exist, you'll have to create them as well.

after upgrading R, can I automatically update the packages [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 specify lib directory when installing development version R Packages from github repository

In Ubuntu, I am installing all the R packages in the directory, /usr/lib/R/site-library by specifying lib option in install.packages().
But when I try to install the development version of the R packages using, install_github(), it always installs in a local repository of the system user.
.libPaths() has 4 directories including the local repository. So, I have 2 questions,
Will it install in any of the other 3 repositories if i remove the local repository from .libPaths()?
Is there any way to specify installation library path in install_github()?
I am using Ubuntu 12.04 64bit and R 3.0.1
----------------------UPDATE--------------------------------
Unable to remove the local repository from .libPaths()
If I try to install using install_github() in RStudio, it installs in the local repository since lib is not specified.
If I try to install using install_github() as non-root user, it installs in the local repository since lib is not specified.
If I try to install using install_github() as root user, it installs in the /usr/local/lib/R/site-library since lib is not specified.
Is there any to specify installation lib?
To add specified library paths in devtools, we need to use with_libpaths()
Arguments for with_libpaths() are, with_libpaths(new, code)
Following is an example for using with_libpaths(),
library(devtools)
with_libpaths(new = "/usr/lib/R/site-library/", install_github('rCharts', 'ramnathv'))
Courtesy: Hadley, here :)
And other than with_libpaths(), there are more options for in devtools::with_something()
in_dir: working directory
with_collate: collation order
with_envvar: environmental variables
with_libpaths: library paths, replacing current libpaths
with_lib: library paths, prepending to current libpaths
with_locale: any locale setting
with_options: options
with_path: PATH environment variable
with_par: graphics parameters
More explanations here
install_github takes a ... argument that passes to devtools::install. devtools::install has an args argument.
args
An optional character vector of additional command line arguments to be passed to R CMD install. This defaults to the value of the option "devtools.install.args".
R CMD install takes a library argument
Options:
-h, --help print short help message and exit
-v, --version print INSTALL version info and exit
-c, --clean remove files created during installation
--preclean remove files created during a previous run
-d, --debug turn on debugging messages
and build a debug DLL
-l, --library=LIB install packages to library tree LIB
So the following should work:
devtools::install_github("repo", args = c('--library="./mypath/gdfgdg/"'))
however it doesnt appear to be replacing the call to R CMD install
"C:/PROGRA~1/R/R-31~1.0/bin/x64/R" --vanilla CMD INSTALL \
"C:\Users\john\AppData\Local\Temp\RtmpucrXMD/RSelenium_1.3.2.tar.gz" \
--library="C:/Users/john/Documents/R/win-library/3.1" --install-tests \
--library="C:/Users/john/Desktop/"
This is more of a workaround, but I found a way using the command-line version of R.
Starting from Ubuntu:
sudo -i R
the trick (I found) is to use -i option
Then from R:
.libPaths()
my local R directory does not appear; the default directory is the one that I want.
Then, I install.packages() or install_github() with impunity.
Hope this helps,
Ian

Error in RStudioGD() : Shadow graphics device error: r error 4 (R code execution error)

I am trying to plot using Rstudio. But when I do, plot(cars) which is the basic function, I am getting an Graphics Error in R.
Here is what I have done :
> plot(cars)
Error in RStudioGD() :
Shadow graphics device error: r error 4 (R code execution error)
Please guide me through.
Solution for error:
Error in RStudioGD() :
Shadow graphics device error: r error 4 (R code execution error)
In R Studio, navigate to Tools, Global, Graphics (top middle), set Backend to AGG*, Apply, Ok
*Depending on your system/installation, you may have other other options in the drop down. Ex. AGG, Cairo, Cairo PNG.
AGG is a package which provides graphic devices for R based on the AGG library developed by the late Maxim Shemanarev. AGG provides both higher performance and higher quality than the standard raster devices provided by grDevices. You might need to install AGG. Compatible with R Studio since v1.4.
https://ragg.r-lib.org/
Initially, I reinstalled RStudio to the newest version (1.1.442) and, following many advice also the R-base* system (getting to R 3.4.3) using aptitude in the following way:
sudo aptitude reinstall libpangocairo-1.0-0 libpango-1.0-0
sudo aptitude reinstall r-base r-base-core r-base-dev
I used aptitude because it is usually better than apt-get to disentangle intricate dependency trees. Afterwards, when no package was loaded into the environment it was working just fine but any package loading was creating a whole variety of DLL-related errors as follows.
FINAL SOLUTION (NO NEED OF REINSTALL):
The error was showing again as soon as I loaded my self-made library. The real problem is the number of open DLL. If you load too many packages or files you will get to the limit and you will have error messages between maximal number of DLLs reached... or failed to load cairo DLL (this error warning) or even lapack routines cannot be loaded. I had these three error randomly as I loaded my full-of-dependencies-homemade-library.
So I started again looking for a solution. The final one is to allow more DLL and to do so it is enough to set the environmental variable R_MAX_NUM_DLLS to a higher number (I set it to 500). In order to avoid the hassle of setting it every time you can read ?Startup documentation and consequently write R_MAX_NUM_DLLS=500 in your Renviron file R-HOME/etc/Renviron.site. In my case (Ubuntu:16.04 it was /usr/lib/R/etc/Renviron.site. This fixed smoothly the problem.
Thank goodness, I just exited Rstudio and relaunched and the problem went away
Under Ubuntu 13.10
I had the similar issue with rstudio server, tried all different suggestions no work.
Finally figured out this way:
sudo service rstudio-server stop
remove all rstudio related files (sudo find / -name "rstudio" | xargs sudo rm -r)
uninstall R: sudo apt-get remove r-base-core r-base r-base-dev
remove all R related files (sudo find / -name "R" | xargs sudo rm -r)
re-install R: sudo apt-get install r-base-core r-base r-base-dev
test R: making sure plot(cars) works in R, output a pdf file.
re-install R studio server: http://www.rstudio.com/ide/download/server
I had the same issue and found James Mao's answer helpful, but I wanted to avoid reinstalling R so that I would not have to also reinstall all of my R packages. I was able to fix the issue by reinstalling RStudio without reinstalling R, which makes sense because the error is with RStudio, not R itself. Here are the instructions:
sudo service rstudio-server stop
remove all rstudio related files (sudo find / -name "rstudio" | xargs sudo rm -r)
re-install R studio server: http://www.rstudio.com/ide/download/server
Reinstall the package ggplot2 (install.packages"ggplot2") and invoke the library. It must work then
I meet this today, reindatall Rstudio still can't solve. finally installed textshaping
install.packages('textshaping'). It's ok now
I had the following error in a CentOS:7 Docker container when running rstudio-server verify-installation:
27 Feb 2017 14:17:09 [rsession-rstudio-server] ERROR r error 4 (R code execution error) [errormsg=Error in system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE) :
error in running command
]; OCCURRED AT: rstudio::core::Error rstudio::r::exec::<unnamed>::evaluateExpressionsUnsafe(SEXPREC*, SEXPREC*, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::<unnamed>::EvalType) /root/rstudio/src/cpp/r/RExec.cpp:159; LOGGED FROM: rstudio::core::FilePath rstudio::session::module_context::findProgram(const std::string&) /root/rstudio/src/cpp/session/SessionModuleContext.cpp:879
27 Feb 2017 14:17:09 [rsession-rstudio-server] ERROR r error 4 (R code execution error) [errormsg=Error in system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE) :
error in running command
]; OCCURRED AT: rstudio::core::Error rstudio::r::exec::<unnamed>::evaluateExpressionsUnsafe(SEXPREC*, SEXPREC*, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::<unnamed>::EvalType) /root/rstudio/src/cpp/r/RExec.cpp:159; LOGGED FROM: rstudio::core::FilePath rstudio::session::module_context::findProgram(const std::string&) /root/rstudio/src/cpp/session/SessionModuleContext.cpp:879
I fixed it by installing which command: yum install which
I had the same error and am on Ubuntu. I did not install R through sudo apt-get install r-base but instead downloaded a specific version, unpacked it and installed it manually with:
./configure --with-readline=no --with-x=no --enable-R-shlib
make
sudo make install
I did not have cairograpghics installed, which is apparently important to build 2D graphics with R. So I installed that with:
sudo apt-get install libcairo2-dev
Or find the version for your OS here: https://www.cairographics.org/download/
I then uninstalled R again by simply going into the downloaded R folder that I had previously compiled using the above commands mentioned and typed:
sudo make uninstall
And then I configured and installed the same R version again. That did it. The uninstall and reinstall was important, just installing cairographics didnt work, you have to have it installed before using ./configure.
I had the same problem (even though I had been using the same installation for over a year without this problem).
I just needed to restart the computer and everything was good again.
:D

Resources