Trouble installing package rms for Rstudio - r

I have been having an issue installing package rms. I am trying to interpret ordinal models (using the package ordinal) and plot regressions using them. For rms, I don't even get an error, just that it updates other loaded packages, loads and attaches package 'lubridate' which had already been installed, and that 'date' is masked from the base package.
For reference I had originally tried to install hmisc, which I found out was a dependency for rms. This led to an issue installing dependency gfortran. When I attempt to install gfortran, I get
package ‘gfortran’ is not available (for R version 3.5.1)
But then, when I try to install Hmisc, I get
installing the source package ‘Hmisc’
trying URL 'https://cran.rstudio.com/src/contrib/Hmisc_4.4-0.tar.gz'
Content type 'application/x-gzip' length 744545 bytes (727 KB)
==================================================
downloaded 727 KB
* installing *source* package ‘Hmisc’ ...
** package ‘Hmisc’ successfully unpacked and MD5 sums checked
** libs
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/include -fPIC -Wall -g -O2 -c Hmisc.c -o Hmisc.o
gfortran -fPIC -g -O2 -c cidxcn.f -o cidxcn.o
make: gfortran: No such file or directory
make: *** [cidxcn.o] Error 1
ERROR: compilation failed for package ‘Hmisc’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Hmisc’
Warning in install.packages :
installation of package ‘Hmisc’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/5l/r40ht3p511j0mbty0ptcc7zm0000gn/T/RtmpFAI0pw/downloaded_packages’
For reference, I run this on a Mac OS Catalina (10.15.4).
Alternatively, if you have any other ways to graph regressions using ordinal models please let me know! Thank you very much.

I got a similar error even though I had installed gfortran by running brew install gfortran. But I needed to add this to my ~/.Rprofile:
Sys.setenv(PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin")

Related

R can't find icc to compile packages

I've compiled R-mkl package in Arch Linux using the Intel OneAPI compilers. But I cannot install packages from inside R, since it cannot find icc. The path in order to bash find the executables is defined in /etc/bash.bashrc:
export PATH="$PATH:/opt/intel/oneapi/compiler/latest/linux/bin/intel64/"
When I try to compile a package, it says it cannot find icc:
> install.packages("lazyeval")
Installing package into ‘/home/juliano/R/x86_64-pc-linux-gnu-library/4.2’
(as ‘lib’ is unspecified)
tentando a URL 'https://cran.rstudio.com/src/contrib/lazyeval_0.2.2.tar.gz'
Content type 'application/x-gzip' length 83482 bytes (81 KB)
==================================================
downloaded 81 KB
* installing *source* package ‘lazyeval’ ...
** package ‘lazyeval’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
icc -std=gnu11 -I"/usr/include/R/" -DNDEBUG -I/usr/local/include -fpic -O3 -fPIC -m64 -march=native -fp-model precise -fp-model source -I/opt/intel/mkl/include -c expr.c -o expr.o
/bin/sh: linha 1: icc: command not found
make: *** [/usr/lib64/R/etc/Makeconf:169: expr.o] Erro 127
ERROR: compilation failed for package ‘lazyeval’
* removing ‘/home/juliano/R/x86_64-pc-linux-gnu-library/4.2/lazyeval’
Warning in install.packages :
installation of package ‘lazyeval’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpPvcR2C/downloaded_packages’
How I do instruct R to read /etc/bash.bashrc or define the path to the compilers manually?
I have also tried to define the path in a file in /etc/profile.d, without success.
You can try sourcing setvars.sh script to initiate the OneAPI environment.
source /opt/intel/oneapi/setvars.sh
As you said, it will work if you create a symlink to the /bin.
Refer to the below link to get more details on usage of R with Intel OneAPI
https://www.intel.com/content/www/us/en/developer/articles/technical/using-onemkl-with-r.html

Why some R packages can't be installed

I've been using R for a while and everything was normal when installing packages. Recently, I upgraded R on my Ubuntu 16.04 from 3.4.4 to 4.0.2 and then I tried to install the package imputeTS as
> install.packages("imputeTS")
Installing package into ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘png’, ‘gridtext’, ‘ggtext’
trying URL 'https://cloud.r-project.org/src/contrib/png_0.1-7.tar.gz'
Content type 'application/x-gzip' length 24990 bytes (24 KB)
==================================================
downloaded 24 KB
trying URL 'https://cloud.r-project.org/src/contrib/gridtext_0.1.1.tar.gz'
Content type 'application/x-gzip' length 441462 bytes (431 KB)
==================================================
downloaded 431 KB
trying URL 'https://cloud.r-project.org/src/contrib/ggtext_0.1.0.tar.gz'
Content type 'application/x-gzip' length 1849875 bytes (1.8 MB)
==================================================
downloaded 1.8 MB
trying URL 'https://cloud.r-project.org/src/contrib/imputeTS_3.1.tar.gz'
Content type 'application/x-gzip' length 3015320 bytes (2.9 MB)
==================================================
downloaded 2.9 MB
* installing *source* package ‘png’ ...
** package ‘png’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG `libpng-config --cflags` -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c read.c -o read.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG `libpng-config --cflags` -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c write.c -o write.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o png.so read.o write.o -L/home/.../anaconda/lib -lpng16 -lm -lz -lm -L/usr/lib/R/lib -lR
installing to /home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so':
libpng16.so.16: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/png’
ERROR: dependency ‘png’ is not available for package ‘gridtext’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/gridtext’
ERROR: dependency ‘gridtext’ is not available for package ‘ggtext’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/ggtext’
ERROR: dependency ‘ggtext’ is not available for package ‘imputeTS’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/imputeTS’
The downloaded source packages are in
‘/tmp/RtmpZubgYt/downloaded_packages’
Warning messages:
1: In install.packages("imputeTS") :
installation of package ‘png’ had non-zero exit status
2: In install.packages("imputeTS") :
installation of package ‘gridtext’ had non-zero exit status
3: In install.packages("imputeTS") :
installation of package ‘ggtext’ had non-zero exit status
4: In install.packages("imputeTS") :
installation of package ‘imputeTS’ had non-zero exit status
Then
> library(imputeTS)
Error in library(imputeTS) : there is no package called ‘imputeTS’
I tried to install the same package as install.packages("imputeTS", dependencies = TRUE) but this gave me the same result installation of package ‘imputeTS’ had non-zero exit status
Following, I tried to install the packages Hmisc and mice. The same result was for the first package where as mice was installed successfully!
Two more comments, the first is this statement (as ‘lib’ is unspecified) started to appear just after upgrading R. The second, I am not sure if related, is that there is no space on my linux!
So how could I install the needed packages successfuly?
Just a wrap up that people can find the correct answer given in the comments better and understand the error messages
This is no problem related specifically to the imputeTS package.
This can be seen in this part of the error message
Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so':
libpng16.so.16: cannot open shared object file: No such file or directory
The error actually occurs while trying to install the png package.
How is this related to the imputeTS package?
You can see this here:
ERROR: loading failed
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/png’
ERROR: dependency ‘png’ is not available for package ‘gridtext’
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/gridtext’
ERROR: dependency ‘gridtext’ is not available for package ‘ggtext’
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/ggtext’
ERROR: dependency ‘ggtext’ is not available for package ‘imputeTS’
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/imputeTS’
R packages build on each other and import functions of other packages. In this case imputeTS imports ggtext, which imports gridtext, which imports png.
So quite a sequence of dependencies and if installation of png fails, this affects all the other packages.
Luckily this part of the error message also gives a hint, what could be wrong:
unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so':
libpng16.so.16: cannot open shared object file: No such file or directory
There is a library missing on which the png package itself depends on. Without this library the installation of png will fail and cause all these mentioned issues.
So just install the library like this:
sudo apt-get install libpng16-16

error while installing vegan in r

When I tried to install vegan using install.packages("vegan") and using RStudio I am getting the following error message
* installing *source* package ‘vegan’ ...
** package ‘vegan’ successfully unpacked and MD5 sums checked
** libs
gfortran -fpic -g -O2 -fstack-protector-strong -c cepin.f -o cepin.o
/bin/bash: gfortran: command not found
/usr/lib/R/etc/Makeconf:157: recipe for target 'cepin.o' failed
make: *** [cepin.o] Error 127
ERROR: compilation failed for package ‘vegan’
* removing ‘/home/stephy/R/x86_64-pc-linux-gnu-library/3.2/vegan’
Warning in install.packages :
installation of package ‘vegan’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpoFztoS/downloaded_packages’
You need to install GFortran and make sure that it is in your PATH.
You can download a binary of it for your OS from here:
https://gcc.gnu.org/wiki/GFortranBinaries
Since you're on Linux after downloading it you can install it like this:
tar -xzvf gfortran-4.5-linux-i686.tar.gz -C /
Then add it to your PATH then try installing vegan again.

How to determine which older version of the R package is compatible with my R version

I am trying to install the "tm" package but then I get an error saying that "tm" is not available for my R version
package ‘tm’ is not available (for R version 3.0.2)
But then I saw that someone suggested I download the archived version from
http://cran.r-project.org/src/contrib/Archive/tm/?C=M;O=A
and then try installing from source.
My question is how do I determine which file there in the list is compatible with my R version?
I developed an answer related to the approach here, but which uses only base R (you don't need XML or devtools or anything). It also potentially handles some contingencies that may not be addressed by the solution I linked to from the other question. Since it was around 100 lines of code, rather than just post a huge function here, I rolled it into a package oldr you can get from GitHub here:
oldr package GitHub repo
The package has just one exported function, install.compatible.packages(). I have tested it on Ubuntu 18.04. I installed R 3.1.0 and installed tm (and its dependencies). The current version of tm requires R 3.2.0, so wouldn't be available via install.packages(), but my function allows its installation:
> oldr::install.compatible.packages("NLP")
Installing package into ‘/home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘NLP’ ...
** package ‘NLP’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (NLP)
> oldr::install.compatible.packages("slam")
Installing package into ‘/home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘slam’ ...
** package ‘slam’ successfully unpacked and MD5 sums checked
** libs
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c apply.c -o apply.o
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c grouped.c -o grouped.o
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c sparse.c -o sparse.o
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c util.c -o util.o
gcc -shared -L/usr/local/lib -o slam.so apply.o grouped.o sparse.o util.o -L/opt/R/3.1.0/lib/R/lib -lRblas -lgfortran -lm -lquadmath -L/opt/R/3.1.0/lib/R/lib -lR
installing to /home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1/slam/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (slam)
> oldr::install.compatible.packages("tm")
Installing package into ‘/home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘tm’ ...
** package ‘tm’ successfully unpacked and MD5 sums checked
** libs
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c copy.c -o copy.o
gcc -shared -L/usr/local/lib -o tm.so copy.o -L/opt/R/3.1.0/lib/R/lib -lR
installing to /home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1/tm/libs
** R
** data
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (tm)
Update: Testing on Windows
I now have also had the chance to test on Windows (8.1), and everything worked smoothly for installing tm to an old version of R (v. 3.1.0):
> oldr::install.compatible.packages("NLP")
Installing package into ‘C:/Users/User/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://mirror.las.iastate.edu/CRAN/bin/windows/contrib/3.1/NLP_0.1-9.zip'
Content type 'application/zip' length 278699 bytes (272 Kb)
opened URL
downloaded 272 Kb
package ‘NLP’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\RtmpojDNlF\downloaded_packages
> oldr::install.compatible.packages("slam")
Installing package into ‘C:/Users/User/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://mirror.las.iastate.edu/CRAN/bin/windows/contrib/3.1/slam_0.1-32.zip'
Content type 'application/zip' length 111528 bytes (108 Kb)
opened URL
downloaded 108 Kb
package ‘slam’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\RtmpojDNlF\downloaded_packages
> oldr::install.compatible.packages("tm")
Installing package into ‘C:/Users/User/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://mirror.las.iastate.edu/CRAN/bin/windows/contrib/3.1/tm_0.6-2.zip'
Content type 'application/zip' length 710798 bytes (694 Kb)
opened URL
downloaded 694 Kb
package ‘tm’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\RtmpojDNlF\downloaded_packages
Update: Additional Parameters
Now users can specify which version of R to attempt installation for (R_version parameter), and which directory to install packages to (lib parameter), which could be useful for testing or other purposes.
You can use the METACRAN mirror:
Go to the blame page of the DESCRIPTION file of the package you're interested in.
E.g. for tm: https://github.com/cran/tm/blame/master/DESCRIPTION
Find the Depends line and click as many times as needed on the View blame prior to this change icon, until an old enough R version is displayed.
If you want to automate that, it may be better to use crandb (also from METACRAN).
Side note: sometimes package authors list R (≥ x.y.z) as a dependency just to be safe because they use version x.y.z and didn't do any tests with previous versions.
You can download the archived package and then untar and un-gzip it. The DESCRIPTION file lists the version of R that it needs. In your case the file tm_0.5-10.tar.gz (that is, the most recent archive version, but not the current version) has this line:
Depends: R (>= 3.0.0)
Version 0.6 of the tm package updated its dependency to R greater than or equal to 3.1.0.
Another option would be to upgrade your version of R so it is compatible with that latest version of the "tm" package. You can do that easily within R by using the following code:
# install the latest installr package:
install.packages("installr")
# require the latest installr package:
require(installr)
#run the command to update R
updateR()
HT: http://www.r-statistics.com/2014/07/r-3-1-1-is-released-and-how-to-quickly-update-it-on-windows-os/
You can use the groundhog package.
First, to find the dates you can use the cross.toc() function, which will show all publication dates for the selected packages, including R itself.
For example, to get the publication dates for tm and R:
library(groundhog)
cross.toc(c("tm","R"))
You will get something like this:
132 3.6.1 2019-07-05 R
133 3.6.2 2019-12-12 R
134 0.7-7 2019-12-13 tm
135 3.6.3 2020-02-29 R
136 4.0.0 2020-04-24 R
If you are using R 3.6.1 you would choose a date after 2019-07-05, if you wanted the version 0.7-7 of tm a date after 2019-12-13, and then load that version with
groundhog.library('tm', '2019-12-15')

R install `KFKSDS` on mac

I am trying to install tsoutliers library in R where only the source is available and it doesn't has a CRAN package available. Also, KFKSDS in one of the dependencies that have to be installed, again, it is source code version available only.
I used brew to have gsl installed but when I tried to install KFKSDS, it still errorred out. On the other side, I installed gsl, gsl-devel, KFKSDS and tsoutliers easily on the redhat server. Can anyone show me how can I installed it successfully on my Mac. I am using R 3.1.1 which is not cutting edge but should be good enough, I guess.
> install.packages("KFKSDS", type="source")
trying URL 'http://cran.rstudio.com/src/contrib/KFKSDS_1.5.tar.gz'
Content type 'application/x-gzip' length 30272 bytes (29 Kb)
opened URL
==================================================
downloaded 29 Kb
* installing *source* package ‘KFKSDS’ ...
** package ‘KFKSDS’ successfully unpacked and MD5 sums checked
** libs
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -fPIC -mtune=core2 -g -O2 -c KF-deriv.cpp -o KF-deriv.o
In file included from /usr/include/c++/4.2.1/bits/locale_facets.h:1539,
from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from /usr/include/c++/4.2.1/numeric:67,
from KFKSDS.h:12,
from KF-deriv.cpp:1:
/usr/include/c++/4.2.1/bits/codecvt.h:219:45: error: macro "length" passed 4 arguments, but takes just 1
In file included from /usr/include/c++/4.2.1/bits/locale_facets.h:1539,
from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from /usr/include/c++/4.2.1/numeric:67,
from KFKSDS.h:12,
from KF-deriv.cpp:1:
/usr/include/c++/4.2.1/bits/codecvt.h:218: error: expected ‘;’ before ���const’
/usr/include/c++/4.2.1/bits/codecvt.h:222: error: expected `;' before ‘int’
make: *** [KF-deriv.o] Error 1
ERROR: compilation failed for package ‘KFKSDS’
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/KFKSDS’
Warning in install.packages :
installation of package ‘KFKSDS’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/d2/ffftfj193ng339zrc3jbdv75m9ssv9/T/RtmpgJshhe/downloaded_packages’

Resources