Install sf for r using gdal from postgresapp - r

I am on MacOSX 11.4 Big Sur.
I have just installed on my computer https://postgresapp.com, which bundles PostgreSQL together with the needed libraries for PostGIS (proj, geos, and gdal).
I am able to use command line functions like ogr2ogr, gdalinfo etc. from my terminal, indicating that gdal is successfully installed.
I now want to install the "sf" package for R version 4.1.0. I am able to successfully install "sf", but the PostgreSQL driver is missing when I use the native installation
install.packages("sf")
According to the sf documentation and things I have read elsewhere on stack, this is a known issue for MacOSx, and the recommended workaround for this problem is to separately install gdal using homebrew or the kyngchaos binaries. However, I would like to use the gdal installation used by the postgresapp binary mentioned earlier so that there is only one installation on my computer..
According to the postgresapp installation documentation (https://postgresapp.com/documentation/install.html), the relevant paths are:
Binaries: /Applications/Postgres.app/Contents/Versions/latest/bin
Headers: /Applications/Postgres.app/Contents/Versions/latest/include
Libraries: /Applications/Postgres.app/Contents/Versions/latest/lib
Therefore, when combined with the "sf" documentation my assumption is that the following should work.
install.packages("sf", configure.args = "--with-gdal-lib=/Applications/Postgres.app/Contents/Versions/latest/lib/"
Although I receive no errors or warnings, this does not fix the problem for me as sf::st_drivers() still does not list the PostgreSQL driver as an option. Can someone please help me figure out what additional configuration arguments, if any, are needed to get sf to recognise the Postgres driver?

Related

Unable to install `sf `on R version 4.1.2

I upgrade to R version 4.1.2 but now I cannot install sf package because the package it not available for this version of R supposedly
I downloaded the file from 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-4.tgz' and try to install from a local file because when I tried to use install.packages("sf") the download timeout
Please could somebody provide some ideas of what I am doing wrong?
Try
install.packages(file.choose(), repos = NULL)
This will both (1) tell R that you are installing from a local file; (2) allow you to choose the file interactively, making sure that you're not making a mistake with the name or the extension.
I don't think you'll need type = "source" in this case, but it wouldn't hurt.
If you do need to install from source, be prepared for the fact that sf needs several external, system libraries:
SystemRequirements: C++11, GDAL (>= 2.0.1), GEOS (>= 3.4.0), PROJ (>=
4.8.0), sqlite3
It might be worth trying the installation from the repository again (possibly after setting options(timeout = 600) as suggested by #jared_mamrot) — it might be a transient problem — since that will skip any headaches with installing system libraries.

R package build failing on Unix machines due to missing GSL - GNU Scientific Library

I am facing a particularly vexing problem with R package development. My own package, called ggstatsplot (https://github.com/IndrajeetPatil/ggstatsplot), depends on userfriendlyscience, which depends on another package called MBESS, which itself ultimately depends on another package called gsl. There is no problem at all for installation of ggstatsplot on a Windows machine (as assessed by AppVeyor continuous integration platform: https://ci.appveyor.com/project/IndrajeetPatil/ggstatsplot).
But whenever the package is to be installed on Unix machines, it throws the error that ggstatsplot can't be downloaded because userfriendlyscience and MBESS can't be downloaded because gsl can't be downloaded. The same thing is also revealed on Travis continuous integration platform with virtual Unix machines, where the package build fails (https://travis-ci.org/IndrajeetPatil/ggstatsplot).
Now one way to solve this problem for the user on the Unix machine is to configure GSL (as described here:
installing R gsl package on Mac), but I can't possibly expect every user of ggstatsplot to go through the arduous process of configuring GSL. I want them to just run install.packages("ggstatsplot") and be done with it.
So I would really appreciate if anyone can offer me any helpful advice as to how I can make my package user's life simpler by removing this problem at its source. Is there something I should include in the package itself that will take care of this on behalf of the user?
This may not have a satisfying solution via changes to your R package (I'm not sure either way). If the gsl package authors (which include a former R Core member) didn't configure it to avoid a pre-req installation of a linux package, there's probably a good reason not to.
But it may be some consolation that most R+Linux users understand that some R packages first require installing the underlying Linux libraries (eg, through apt or dnf/yum).
Primary Issue: making it easy for the users to install
Try to be super clear on the GitHub readme and the CRAN INSTALL file. The gsl package has decent CRAN directions. This leads to the following bash code:
sudo apt-get install libgsl0-dev
The best example of clear (linux pre-req package) documentation I've seen is from the curl and sf packages. sf's CRAN page lists only the human names of the 3 libraries, but the GitHub page provides the exact bash commands for three major distribution branches. The curl package does this very well too (eg, CRAN and GitHub). For example, it provides the following explanation and bash code:
Installation from source on Linux requires libcurl. On Debian or Ubuntu use libcurl4-openssl-dev:
sudo apt-get install -y libcurl-dev
Ideally your documentation would describe how do install the gsl linux package on multiple distributions.
Disclaimer: I've never developed a package that directly requires a Linux package, but I use them a lot. In case more examples would help, this doc includes a script I use to install stuff on new Ubuntu machines. Some commands were stated explicitly in the package documentation; some had little or no documentation, and required research.
edit 2018-04-07:
I encountered my new favorite example: the sys package uses a config file to produce the following message in the R console. While installing 100+ packages on a new computer, it was nice to see this direct message, and not have to track down the R package and the documentation about its dependencies.
On Debian/Ubuntu this package requires AppArmor.
Please run: sudo apt-get install libapparmor-dev
Another good one is pdftools, that also uses a config file (and is also developed by Jeroen Ooms).
Secondary Issue: installing on Travis
The userfriendly travis config file apparently installs a lot of binaries directly (including gsl), unlike the current ggstatsplot version.
Alternatively, I'm more familiar with telling travis to install the linux package, as demonstrated by curl's config file. As a bonus, this probably more closely replicates what typical users do on their own machines.
addons:
apt:
packages:
- libcurl4-openssl-dev
Follow up 2018-03-13 Indrajeet and I tweaked the travis file so it's working. Two sections were changed in the yaml file:
The libgsl0-dev entry was added under the packages section (similar to the libcurl4-openssl-dev entry above).
Packages were listed in the r_binary_packages section so they install as binaries. The build was timing out after 50 minutes, and now it's under 10 min. In this particular package, the r_binary_packages section was nested in the Linux part of the Travis matrix so it wouldn't interfere with his two OS X jobs on Travis.

"rgdal" installation failed on ubuntu

I use travis to check my R package, it's based on a virtual machine of ubuntu. One of my dependencies is rgdal from CRAN, which cannot be installed correctly on travis.
First it said:
ERROR: dependencies ‘rgdal’ is not available for package ‘my package’
I followed the instruction here, then comes the endless dependencies, I installed one by one, according to the instruction of every trial. Finally I installed packages is as below:
libproj-dev
libcurl4-gnutls-dev
libdap-dev
libgdal-dev
libgdal1h
libhdf5-dev
libhdf5-serial-dev
libgdal-dev
libgdal1-dev
It said I still need to install libhdf5-7 = 1.8.11-3ubuntu1~precise1~ppa1
But when I install package libhdf5-7 = 1.8.11-3ubuntu1~precise1~ppa1, it gives another error:
E: Unable to locate package
E: Unable to locate package 1.8.11-3ubuntu1~precise1~ppa1
E: Couldn't find any package by regex '1.8.11-3ubuntu1~precise1~ppa1'
And it seems no more solutions now.
I wonder how to fix this on travis? Is it a common issue on only travis virtual machine or it could happen on any ubuntu machine? Or the package rgdal has some problems with ubuntu?`
Background:
All my installation above used apt-packages of travis, which is explained as below by travis:
apt_packages: A list of packages to install via apt-get. Common examples here include entries in SystemRequirements. This option is ignored on non-linux builds
As of this week, you can opt into using Ubuntu 14.04 on Travis:
See this blog post from Travis for details
See this .travis.yml where I enable Trusty aka 14.04
Switching to 14.04 may be enough in this case. If not, also note that you can prepare your own .deb packages. I mention this in an blog post from this summer.
As the geospatial packages are a little involved that is probably your best. You would need to know how to build Debian packages, and how to use Launchpad to have them auto-built for you. Both topics have lots of tutorials.

Package installation issues with R 3.1.0

My Fedora system (Fedora 20, all up to date) has just had R updated to version 3.1.0. Since then, I've had issues installing multiple packages. glmnet failed previously, and now I'm having trouble with treemap. More specifically, I get an error during treemap installation that httpuv has zero exit status.
I never had issues with the previous version of R. Any reason this version should have such problems??
There could be many causes to do with your OS, version, permissions, other installed packages/software, etc, etc. Without seeing the full error message it's hard to know.
One possibility specific to httpuv is root privileges. I've noticed a few threads on various forums when searching for installation errors with this package and Linux, many of them mentioning root v. non-root issues. In another case, libuv needed to be upgraded.
I encounter package installation problems daily and I have some more general work-arounds as well. Hopefully one of these will solve your problem.
Install the package from source
download.file(url="http://cran.r-project.org/src/contrib/httpuv_1.3.0.tar.gz", destfile = "httpuv.tar.gz")
install.packages("httpuv.tar.gz", type = "source", repos = NULL)
Install using devtools via GitHub if the package supports it
Install RTools and re-try your package installation
Install an older version of the package
If those above do not work, then I dig deeper by referring to advice given to me by a VP of IT in my company. These comments were made in reference to frequent package installation problems I encountered when switching from Windows to Solaris:
There are two types of install/make problems. Missing .h files
and/or missing .so/.a libs. The reason for these are multiple:
1.- the package that delivers these is not installed. This means that those files cannot be found anywhere in the /usr tree. Solution is
install right package, make sure the files are there
2.- the includes are not found by the install configurator. This means some environment variable or install option is not properly set (this
is our case for RODBC). Figuring out which variable to set is
challenging without looking at the package documentation [fortunately, documentation is not hard to find!]
3.- the libs are not in the LD_LIBRARY_PATH, easy to fix.
4.- There is a deeper compile/link error, meaning the package is not compatible with the rest of the sw, or has not been properly ported.

R: can rpm files be used with Windows for possibly outdated R packages?

I was trying to run code that required the R packages ‘pkgDepTools’ and ‘Rgraphviz’. I received error messages saying that neither package is available for R version 2.15.0.
A Google search turned up the following webpage RPM Pbone that seems to have the packages:
http://rpm.pbone.net/index.php3/stat/4/idpl/17802118/dir/mandrake_other/com/R-pkgDepTools-1.20.0-1-mdv2012.0.i586.rpm.html
and
http://rpm.pbone.net/index.php3/stat/4/idpl/17802080/dir/mandrake_other/com/R-Rgraphviz-1.32.0-2-mdv2012.0.i586.rpm.html
However, the files have an *.rpm extension rather than the *.tar.gz or *.zip extensions I am used to.
I am using Windows 7 and R version 2.15.0. Can I install an R package from an *.rpm file?
From Wikipedia *.rpm seems like maybe it is more for Linux:
http://en.wikipedia.org/wiki/RPM_Package_Manager
Regarding other possible solutions, I have found several earlier posts here with similar questions about installing R packages that are not available for the most recent version of R:
Bivariate Poisson Regression in R?
Package ‘GeneR’ is not available
R Venn Diagram package Venerable unavailable - alternative package?
I have installed the latest version of Rtools and the package 'devtools'. Although I know nothing about them.
There is an archived version of 'Rgraphviz' here:
http://cran.r-project.org/src/contrib/Archive/Rgraphviz/
but I cannot locate an archived version of 'pkgDepTools'.
If I can install the packages on a Windows machine using the above *.rpm files could someone please provide instructions?
If I must use Rtools to build them I might ask more questions because the instructions at the link below are challenging for me:
http://cran.r-project.org/doc/manuals/R-admin.html#Building-from-source
To be completely transparent I am hoping someone might build them for me, if that is possible. Although I recognize the experience and knowledge gained from doing it myself would probably pay off in the long run.
Thank you for any advice.
pkgDepTools and Rgraphviz are BioConductor R packages not ones hosted on CRAN. Unless you configure your R to download packages from those repos, R will report that they are not available; it can only install from repos it has been configured to install from.
To install those BioConductor packages a lite installation method is provided:
source("http://bioconductor.org/biocLite.R")
biocLite(c("pkgDepTools", "Rgraphviz"))
Further details are provided on the Install page of the BioConductor website
In general you can't use rpm packages on Windows; rpm's are the equivalent of a binary package for Linux. Any C/C++/Fortran/etc code will have been compiled for Linux not Windows. If a package really isn't available for your version of R then check if there is a reason stated on CRAN (usually Windows binaries take a few days longer to produce or there may be requirements for software not available on the CRAN Windows build machines). You can try the WinBuilder service run by Uwe Ligges to build Windows Binaries of packages for you, but if the package was on CRAN and now isn't that suggests it no longer works with current R and can not be built.
In general try a wider search for packages; the first hit in my Google search results under the search string "pkgDepTools" is the Bioconductor page for the package which includes a link to the Windows binary and instructions on how to install the package from within R.
I think this merits an answer rather than a comment.
A gentleman at Bioconductor helped me get Rgraphviz installed. The primary problem was that the version of Rgraphviz I had downloaded only seems to work with the 32-bit version of R and I was running a 64-bit version of R. I was able to install Rgraphviz in the 32-bit version of R.
I had also made an error or two in the PATH statement during some of my attempts to install Rgraphviz. However, the post above in my second comment provides the instructions for installation.
You just, it seems, cannot install the normal download version of Rgraphviz in the 64-bit version of R.
I think many of our emails back and forth are now posted on the Bioconductor forum.
I might edit this answer with more detailed instructions in the next 24-hours.

Resources