I have been trying to install glmnet package from RStudio. I have Ubuntu 18.04 running on my system. This is the command I have used
install.packages("glmnet", repos = "http://cran.us.r-project.org")
I have not been able to install the package. Following is the error message.
Installing package into ‘/home/vamshi/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'http://cran.us.r-project.org/src/contrib/glmnet_2.0-16.tar.gz'
Content type 'application/x-gzip' length 3882584 bytes (3.7 MB)
==================================================
downloaded 3.7 MB
* installing *source* package ‘glmnet’ ...
** package ‘glmnet’ successfully unpacked and MD5 sums checked
** libs
gfortran -fpic -g -O2 -fdebug-prefix-map=/build/r-base-oNcpyf/r-base-3.5.1=. -fstack-protector-strong -c glmnet5dp.f -o glmnet5dp.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-oNcpyf/r-base-3.5.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c glmnet_init.c -o glmnet_init.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o glmnet.so glmnet5dp.o glmnet_init.o -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
/usr/bin/x86_64-linux-gnu-ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
/usr/share/R/share/make/shlib.mk:6: recipe for target 'glmnet.so' failed
make: *** [glmnet.so] Error 1
ERROR: compilation failed for package ‘glmnet’
* removing ‘/home/vamshi/R/x86_64-pc-linux-gnu-library/3.5/glmnet’
Warning in install.packages :
installation of package ‘glmnet’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpwiFSth/downloaded_packages’
Please help me out. I have also tried install.packages("glmnet",dependencies="TRUE")
but still getting errors installing.
@saisaran
The output of sessionInfo() is as follows:
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ISLR_1.2
loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1
The problem is here
gfortran -fpic -g -O2 -fdebug-prefix-map=/build/r-base-oNcpyf/r-base-3.5.1=. -fstack-protector-strong -c glmnet5dp.f -o glmnet5dp.o gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-oNcpyf/r-base-3.5.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c glmnet_init.c -o glmnet_init.o gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o glmnet.so glmnet5dp.o glmnet_init.o -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR /usr/bin/x86_64-linux-gnu-ld: cannot find -lgfortran
make: gfortran: cannot find -lgfortran
You either don't have a fortran compiler or its not accessible by your R instance. How you fix that depends on your operating system,
Solution:-
Type these two lines in your terminal, direct quote:
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2 sudo tar fvxj gfortran-4.8.2-darwin13.tar.bz2 -C /
It will download you the gfortran for Mavericks (which is missing in your system at the moment) and will install it in your system. At least, this will solved your problem.