R package sf, install.packages("sf") ERROR
* installing *source* package ‘sf’ ... ** package ‘sf’ successfully unpacked and MD5 sums checked ** using staged installation configure: CC: /data/home/heshuai/Miniconda3/envs/RV_3.6/bin/x86_64-conda_cos6-linux-gnu-cc configure: CXX: /data/home/heshuai/Miniconda3/envs/RV_3.6/bin/x86_64-conda_cos6-linux-gnu-c++ checking for gdal-config... /data/home/heshuai/Miniconda3/envs/RV_3.6/bin/gdal-config checking gdal-config usability... yes configure: GDAL: 3.1.2 checking GDAL version >= 2.0.1... yes checking for gcc... /data/home/heshuai/Miniconda3/envs/RV_3.6/bin/x86_64-conda_cos6-linux-gnu-cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether /data/home/heshuai/Miniconda3/envs/RV_3.6/bin/x86_64-conda_cos6-linux-gnu-cc accepts -g... yes checking for /data/home/heshuai/Miniconda3/envs/RV_3.6/bin/x86_64-conda_cos6-linux-gnu-cc option to accept ISO C89... none needed checking how to run the C preprocessor... /data/home/heshuai/Miniconda3/envs/RV_3.6/bin/x86_64-conda_cos6-linux-gnu-cpp checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking gdal.h usability... yes checking gdal.h presence... yes checking for gdal.h... yes checking GDAL: linking with --libs only... yes checking GDAL: /data/home/heshuai/Miniconda3/envs/RV_3.6/share/gdal/pcs.csv readable... no checking GDAL: checking whether PROJ is available for linking:... yes checking GDAL: checking whether PROJ is available fur running:... ERROR 1: PROJ: proj_create_from_database: Open of /data/home/heshuai/Miniconda3/envs/RV_3.6/share/proj failed ERROR 1: PROJ: proj_create_from_database: Open of /data/home/heshuai/Miniconda3/envs/RV_3.6/share/proj failed ERROR 1: PROJ: proj_create: unrecognized format / unknown name ERROR 6: Cannot find coordinate operations from `' to `' no configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available? ERROR: configuration failed for package ‘sf’ * removing ‘/data/home/heshuai/R/x86_64-conda_cos6-linux-gnu-library/sf’ The downloaded source packages are in ‘/tmp/Rtmp9qEXgU/downloaded_packages’ Warning message: In install.packages("sf") : installation of package ‘sf’ had non-zero exit status
sf 是R中非常重要的包,很多畫圖包都依賴與sf, 然而安裝sf確實是個極大的挑戰,經常出現各種錯誤。但是如上所示的錯誤是最難解決的,經過多番探索終於解決了。如上面錯誤所示,報Proj包錯誤,然而,我用conda安裝的時候GDAL,GEOS和PROJ包都已經安裝好了,並且已經更新到最高版本。安裝錯誤的原因是設置不對,正確的安裝sf方法如下:
install.packages("sf", configure.args = "--with-gdal config=/data/home/heshuai/Miniconda3/bin/gdal-config --with-geos-config=/data/home/heshuai/Miniconda3/bin/geos-config --with-proj include=/data/home/heshuai/Miniconda3/include/ --with-proj-lib=/data/home/heshuai/Miniconda3/lib/")
設置參數如上所示,包括 4部分:
1. --with-gdal-config = /data/home/heshuai/Miniconda3/bin/gdal-config
2. --with-geos-config = /data/home/heshuai/Miniconda3/bin/geos-config
3. --with-proj-include = /data/home/heshuai/Miniconda3/include/
4. --with-proj-lib = /data/home/heshuai/Miniconda3/lib/
在安裝時設置好了之后sf就完美安裝了
* installing *source* package ‘sf’ ... ** package ‘sf’ successfully unpacked and MD5 sums checked ** using staged installation configure: CC: /data/home/heshuai/Miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc configure: CXX: /data/home/heshuai/Miniconda3/bin/x86_64-conda_cos6-linux-gnu-c++ configure: gdal-config set to /data/home/heshuai/Miniconda3/bin/gdal-config checking gdal-config exists... yes checking gdal-config executable... yes checking gdal-config usability... yes configure: GDAL: 3.1.2 checking GDAL version >= 2.0.1... yes checking for gcc... /data/home/heshuai/Miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether /data/home/heshuai/Miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc accepts -g... yes checking for /data/home/heshuai/Miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc option to accept ISO C89... none needed checking how to run the C preprocessor... /data/home/heshuai/Miniconda3/bin/x86_64-conda_cos6-linux-gnu-cpp checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking gdal.h usability... yes checking gdal.h presence... yes checking for gdal.h... yes checking GDAL: linking with --libs only... yes checking GDAL: /data/home/heshuai/Miniconda3/share/gdal/pcs.csv readable... no checking GDAL: checking whether PROJ is available for linking:... yes checking GDAL: checking whether PROJ is available fur running:... yes configure: GDAL: 3.1.2 checking proj.h usability... yes checking proj.h presence... yes checking for proj.h... yes checking PROJ: checking whether PROJ and sqlite3 are available for linking:... yes configure: geos-config set to /data/home/heshuai/Miniconda3/bin/geos-config checking geos-config exists... yes checking geos-config executable... yes checking geos-config usability... yes configure: GEOS: 3.8.1 checking GEOS version >= 3.4.0... yes checking geos_c.h usability... yes checking geos_c.h presence... yes checking for geos_c.h... yes checking geos: linking with -L/data/home/heshuai/Miniconda3/lib -lgeos_c... yes configure: Package CPP flags: -I/data/home/heshuai/Miniconda3/include/ -DHAVE_PROJ_H -I/data/home/heshuai/Miniconda3/include -I/data/home/heshuai/Miniconda3/include configure: Package LIBS: -L/data/home/heshuai/Miniconda3/lib/ -lproj -L/data/home/heshuai/Miniconda3/lib -lgdal -L/data/home/heshuai/Miniconda3/lib -lgeos_c configure: creating ./config.status config.status: creating src/Makevars ** libs x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/data/home/heshuai/Miniconda3/lib/R/include" -DNDEBUG -I/data/home/heshuai/Miniconda3/include/ -DHAVE_PROJ_H -I/data/home/heshuai/Miniconda3/include -I/data/home/heshuai/Miniconda3/include -I'/data/home/heshuai/Miniconda3/lib/R/library/Rcpp/include' -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /data/home/heshuai/Miniconda3/include -I/data/home/heshuai/Miniconda3/include -Wl,-rpath-link,/data/home/heshuai/Miniconda3/lib -fpic -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/home/heshuai/Miniconda3/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base_1595316670215/work=/usr/local/src/conda/r-base-4.0.2 -fdebug-prefix-map=/data/home/heshuai/Miniconda3=/usr/local/src/conda-prefix -c RcppExports.cpp -o RcppExports.o x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/data/home/heshuai/Miniconda3/lib/R/include" -DNDEBUG -I/data/home/heshuai/Miniconda3/include/ -DHAVE_PROJ_H -I/data/home/heshuai/Miniconda3/include -I/data/home/heshuai/Miniconda3/include - ........... ........... ........... ** R ** demo ** inst ** byte-compile and prepare package for lazy loading in method for ‘dbWriteTable’ with signature ‘"PostgreSQLConnection","character","sf"’: no definition for class “PostgreSQLConnection” in method for ‘dbDataType’ with signature ‘"PostgreSQLConnection","sf"’: no definition for class “PostgreSQLConnection” in method for ‘coerce’ with signature ‘"Spatial","sf"’: no definition for class “Spatial” in method for ‘coerce’ with signature ‘"Spatial","sfc"’: no definition for class “Spatial” in method for ‘coerce’ with signature ‘"sf","Spatial"’: no definition for class “Spatial” in method for ‘coerce’ with signature ‘"sfc","Spatial"’: no definition for class “Spatial” in method for ‘coerce’ with signature ‘"XY","Spatial"’: no definition for class “Spatial” in method for ‘coerce’ with signature ‘"crs","CRS"’: no definition for class “CRS” ** help *** installing help indices *** copying figures ** building package indices ** installing vignettes ** testing if installed package can be loaded from temporary location ** checking absolute paths in shared objects and dynamic libraries ** testing if installed package can be loaded from final location ** testing if installed package keeps a record of temporary installation path * DONE (sf) The downloaded source packages are in ‘/tmp/Rtmp3pC2yw/downloaded_packages’ Updating HTML index of packages in '.Library' Making 'packages.html' ... done > library(sf) Linking to GEOS 3.8.1, GDAL 3.1.2, PROJ 7.0.0
參考:https://r-spatial.github.io/sf/
https://github.com/r-spatial/sf/issues/335