How to download Sf package on MacOS - r

I tried a couple of hours to install sf package (on MacOs) by using most of the solutions I encountered on the web but still, it did not work. Let me show, what I did and then what the problem is step by step.
First, I tried the normal thing install.packages("sf") which resulted in the following error.
URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz' deneniyor
Content type 'application/x-gzip' length 93022013 bytes (88.7 MB)
====================================
downloaded 65.3 MB
Warning in install.packages :
downloaded length 68510897 != reported length 93022013
Warning in install.packages :
URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz': Timeout of 60 seconds was reached
Error in download.file(url, destfile, method, mode = "wb", ...) :
download from 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz' failed
Warning in install.packages :
download of package ‘sf’ failed
Following that, I tried to comply with the instructions in this website https://github.com/r-spatial/sf. To this end, I first installed home brew and then rendered these two codes on the MacOS terminal.
brew install pkg-config
brew install gdal
And, finally, in line with the website's suggestion, I run this code to install rgdal package to get sf installed.
install.packages("rgdal", configure.args = c("--with-proj-lib=/usr/local/lib/", "--with-proj-include=/usr/local/include/"))
However, it came with the following error.
There is a binary version available but the source version is later:
binary source needs_compilation
rgdal 1.5-26 1.5-27 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘rgdal’
URL 'https://cran.rstudio.com/src/contrib/rgdal_1.5-27.tar.gz' deneniyor
Content type 'application/x-gzip' length 4391149 bytes (4.2 MB)
==================================================
downloaded 4.2 MB
* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
** using staged installation
configure: R_HOME: /Library/Frameworks/R.framework/Resources
configure: CC: clang -mmacosx-version-min=10.13
configure: CXX: clang++ -mmacosx-version-min=10.13 -std=gnu++14
configure: CFLAGS: -Wall -g -O2
configure: CPPFLAGS: -I/usr/local/include
configure: CXXFLAGS: -Wall -g -O2
configure: LDFLAGS: -L/usr/local/lib
configure: LDFLAGS: -L/usr/local/lib
configure: CXX11 is: clang++ -mmacosx-version-min=10.13, CXX11STD is: -std=gnu++11
configure: CXX is: clang++ -mmacosx-version-min=10.13 -std=gnu++11
configure: C++11 support available
configure: rgdal: 1.5-27
checking for /usr/bin/svnversion... no
configure: svn revision: 1148
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal’
Warning in install.packages :
installation of package ‘rgdal’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/tc/g15hmz9s0hg1nxmh7_4mw9lm0000gn/T/RtmplfPV9h/downloaded_packages’
As suggested in this website https://github.com/r-spatial/sf, I alternatively tried the solutions in https://github.com/r-spatial/sf/issues/1536#issuecomment-727342736.
Yet, in the part 2, when I run this code chunk,
install.packages("rgeos", repos="http://R-Forge.R-project.org", type="source")
install.packages("rgdal", repos="http://R-Forge.R-project.org", type="source")
library(devtools)
install_github("r-spatial/sf", configure.args = "--with-proj-lib=/usr/local/lib/")
A similar problem emerged for all these codes. For instance, for the first one, the error was;
URL 'http://R-Forge.R-project.org/src/contrib/rgeos_0.5-8.tar.gz' deneniyor
Content type 'application/x-gzip' length 276303 bytes (269 KB)
==================================================
downloaded 269 KB
* installing *source* package ‘rgeos’ ...
** using staged installation
configure: CC: clang -mmacosx-version-min=10.13
configure: CXX: clang++ -mmacosx-version-min=10.13 -std=gnu++14
configure: rgeos: 0.5-7
checking for /usr/bin/svnversion... no
cat: inst/SVN_VERSION: No such file or directory
configure: svn revision:
checking for geos-config... no
no
configure: error: geos-config not found or not executable.
ERROR: configuration failed for package ‘rgeos’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgeos’
Warning in install.packages :
installation of package ‘rgeos’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/tc/g15hmz9s0hg1nxmh7_4mw9lm0000gn/T/RtmplfPV9h/downloaded_packages’
And lastly, I followed the instructions to solve this problem on this website; trouble installing "sf" due to "gdal"
First: gdalinfo --version code resulted in GDAL 3.3.2, released 2021/09/01
Second, I did brew unlink gdal, yet when I run brew link --force gdal2, it did not work. (I am a new user so I assumed it might be because of different versions but when I tried brew link --force gdal3.3.2, it gave me the error Error: No such keg: /opt/homebrew/Cellar/gdal3.3.2.
So, if you can help me how to install sf on MacOS, I will be very glad for that.

The error message lines "Warning in install.packages : downloaded length 68510897 != reported length 93022013" and "Timeout of 60 seconds was reached" suggests the package didn't download properly - this can occur when it takes longer than 60 seconds to download the package to your computer for installation i.e. the "timeout" of 60 seconds is reached.
One solution (the solution that worked in this case) is to increase the amount of time R will wait to download the package by running options(timeout = 1200) before running install.packages("sf")
If you need to build packages from source (with or without openMP) on an M1 mac, I believe the instructions posted here work: https://stackoverflow.com/a/68275558/12957340

Not sure if this is helpful, but I was having similar trouble getting this installed on a fresh Mac. I ended up installing XQuartz (which I didn't have), downloading homebrew to get PROJ, and then reinstalling R (50/50 as to whether I downloaded the right version for my M1 Mac) and got everything installed properly.

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

monocle3 installation issues

I have R 4.2.1 and the latest R studio build 554 on a macOS Monterey.
I am trying to install monocle3 using the following :
BiocManager::install('monocle3')
I get a really long error message
BiocManager::install("monocle3")
'getOption("repos")' replaces Bioconductor standard repositories, see '?repositories' for details
replacement repositories:
CRAN: https://cran.rstudio.com/
Bioconductor version 3.15 (BiocManager 1.30.19), R 4.2.1 (2022-06-23)
Installing package(s) 'monocle3'
Old packages: 'processx', 'ps', 'tm', 'zip'
Update all/some/none? [a/s/n]:
a
There are binary versions available but the source versions are later:
binary source needs_compilation
processx 3.7.0 3.8.0 TRUE
ps 1.7.1 1.7.2 TRUE
tm 0.7-8 0.7-9 TRUE
zip 2.2.1 2.2.2 TRUE
Do you want to install from sources the packages which need compilation? (Yes/no/cancel) yes
installing the source packages ‘processx’, ‘ps’, ‘tm’, ‘zip’
trying URL 'https://cran.rstudio.com/src/contrib/processx_3.8.0.tar.gz'
Content type 'application/x-gzip' length 162539 bytes (158 KB)
==================================================
downloaded 158 KB
trying URL 'https://cran.rstudio.com/src/contrib/ps_1.7.2.tar.gz'
Content type 'application/x-gzip' length 129096 bytes (126 KB)
==================================================
downloaded 126 KB
trying URL 'https://cran.rstudio.com/src/contrib/tm_0.7-9.tar.gz'
Content type 'application/x-gzip' length 638649 bytes (623 KB)
==================================================
downloaded 623 KB
trying URL 'https://cran.rstudio.com/src/contrib/zip_2.2.2.tar.gz'
Content type 'application/x-gzip' length 103404 bytes (100 KB)
==================================================
downloaded 100 KB
* installing *source* package ‘ps’ ...
** package ‘ps’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -mmacosx-version-min=10.13 -Wall -g -O2 -L/usr/local/lib -Wall px.c -o px
px.c:6:10: fatal error: 'unistd.h' file not found
#include <unistd.h>
^~~~~~~~~~
1 error generated.
make: *** [Makevars:11: px] Error 1
ERROR: compilation failed for package ‘ps’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/ps’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/ps’
* installing *source* package ‘tm’ ...
** package ‘tm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I/usr/local/include -fPIC -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/RcppCommon.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/Rcpp/r/headers.h:62:
In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
In file included from /Users/osman/opt/miniconda3/bin/../include/c++/v1/cmath:305:
/Users/osman/opt/miniconda3/bin/../include/c++/v1/math.h:301:15: fatal error: 'math.h' file not found
#include_next <math.h>
^~~~~~~~
1 error generated.
make: *** [/Library/Frameworks/R.framework/Resources/etc/Makeconf:175: RcppExports.o] Error 1
ERROR: compilation failed for package ‘tm’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/tm’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/tm’
* installing *source* package ‘zip’ ...
** package ‘zip’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -mmacosx-version-min=10.13 -Wall -g -O2 miniz.c zip.c unixutils.c tools/cmdzip.c -o tools/cmdzip
In file included from miniz.c:27:
./miniz.h:156:10: fatal error: 'time.h' file not found
#include <time.h>
^~~~~~~~
1 error generated.
make: *** [Makevars:9: tools/cmdzip] Error 1
ERROR: compilation failed for package ‘zip’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/zip’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/zip’
* installing *source* package ‘processx’ ...
** package ‘processx’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -mmacosx-version-min=10.13 -Wall -g -O2 -L/usr/local/lib -Wall tools/px.c -o tools/px
tools/px.c:11:10: fatal error: 'unistd.h' file not found
#include <unistd.h>
^~~~~~~~~~
1 error generated.
make: *** [Makevars:14: tools/px] Error 1
ERROR: compilation failed for package ‘processx’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/processx’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/processx’
The downloaded source packages are in
‘/private/var/folders/ps/3jjkc4kj1y98mzlpdm3wp5dm0000gn/T/RtmpNbTlti/downloaded_packages’
Warning messages:
1: package ‘monocle3’ is not available for Bioconductor version '3.15'
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
2: In install.packages(update[instlib == l, "Package"], l, repos = repos, :
installation of package ‘ps’ had non-zero exit status
3: In install.packages(update[instlib == l, "Package"], l, repos = repos, :
installation of package ‘tm’ had non-zero exit status
4: In install.packages(update[instlib == l, "Package"], l, repos = repos, :
installation of package ‘zip’ had non-zero exit status
5: In install.packages(update[instlib == l, "Package"], l, repos = repos, :
installation of package ‘processx’ had non-zero exit status
so I tried installing 'processx', 'ps', 'tm', 'zip' individually and now I get the following message:
Warning message:
package ‘monocle3’ is not available for Bioconductor version '3.15'
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
Any idea for how to fix this issue?
I expected the installation to go through but it did not
When I get errors installing a package what I usually do is going to the first package that didn't install properly and try and install it in a different way, and I do the same for the others.
Other mac users had similar issue installing the ps package as you can see in this github issues here https://github.com/r-lib/ps/issues/55
they solved the problem by installing ps package via anaconda:
https://anaconda.org/conda-forge/r-ps

Installing package "quantreg" in R fails with "had non-zero exit status"

My aim is to install the R package "quantreg". In R Studio, I therefore type
install.packages("quantreg")
R Studio then prints:
binary source needs_compilation
quantreg 5.85 5.88 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel)
I consequently write "Yes" and hit enter. The installation then fails with the following output:
installing the source package ‘quantreg’
trying URL 'https://cran.rstudio.com/src/contrib/quantreg_5.88.tar.gz'
Content type 'application/x-gzip' length 1016964 bytes (993 KB)
==================================================
downloaded 993 KB
* installing *source* package ‘quantreg’ ...
** package ‘quantreg’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gfortran -fPIC -Wall -g -O2 -c akj.f -o akj.o
make: gfortran: No such file or directory
make: *** [akj.o] Error 1
ERROR: compilation failed for package ‘quantreg’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/quantreg’
Warning in install.packages :
installation of package ‘quantreg’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/bl/yxw71y6n3ksbktr_vmp65h1m0000gn/T/Rtmpc1SB0G/downloaded_packages’
I am on Mac OS 12.3.1 Monterey and use R version 3.6.3. I use this old version of R (instead of an up-to-date one) because it is required in combination with another program that I use. Therefore, I cannot use newer versions of R.
What could be a possible fix for my problem, so that R installs quantreg without failing?

More trouble Installing rgdal on ubuntu 16.04

This problem installing rgdal is not resolved in other similar questions already posted. I installed gdal using the advice on http://www.sarasafavi.com/installing-gdalogr-on-ubuntu.html and also decribed in other answers like this trouble in installing rgdal on ubuntu 16.04 that means from ppa:ubuntugis.
Then when I try to install rgdal the following error appears
> install.packages("rgdal")
Installing package into ‘/home/leonardo/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/rgdal_1.3-4.tar.gz'
Content type 'application/x-gzip' length 1664774 bytes (1.6 MB)
==================================================
downloaded 1.6 MB
* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
configure: R_HOME: /usr/lib/R
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: C++11 support available
configure: rgdal: 1.3-4
checking for /usr/bin/svnversion... no
configure: svn revision: 766
checking for gdal-config... /home/leonardo/anaconda3/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.2.2
checking GDAL version >= 1.11.4... yes
checking gdal: linking with --libs only... no
checking gdal: linking with --libs and --dep-libs... no
/usr/bin/x86_64-linux-gnu-ld: warning: libproj.so.12, needed by /home/leonardo/anaconda3/lib/libgdal.so, not found (try using -rpath or -rpath-link)
/usr/bin/x86_64-linux-gnu-ld: warning: libpoppler.so.71, needed by /home/leonardo/anaconda3/lib/libgdal.so, not found (try using -rpath or -rpath-link)
/usr/bin/x86_64-linux-gnu-ld: warning: libxerces-c-3.2.so, needed by /home/leonardo/anaconda3/lib/libgdal.so,
...
500 lines more
...
/home/leonardo/anaconda3/lib/libgeos_c.so: undefined reference to `geos::geom::PrecisionModel::PrecisionModel(double)'
collect2: error: ld returned 1 exit status
configure: Install failure: compilation and/or linkage problems.
configure: error: GDALAllRegister not found in libgdal.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/leonardo/R/x86_64-pc-linux-gnu-library/3.5/rgdal’
Warning in install.packages :
installation of package ‘rgdal’ had non-zero exit status
It seems to be a problem with python anaconda that I have previously installed, I removed the anaconda python gdal package using
conda remove gdal
But the problems persist
The only way to solve this was to completely remove anaconda installation, following the instructions on https://conda.io/docs/user-guide/install/linux.html#uninstalling-anaconda-or-miniconda with some minor modifications for ubuntu 16.04, you have to open a terminal and remove the anaconda install directory:
rm -rf ~/anaconda3
rm -rf ~/.condarc ~/.conda ~/.continuum
Edit ~/.bashrc to remove the anaconda directory from your PATH environment variable.
After that the installation of rgdal
install.packages("rgdal")
goes without problems.

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