无法在R中安装“raster”包

hivapdat  于 2023-06-27  发布在  其他
关注(0)|答案(2)|浏览(421)

我试图在R中使用光栅包,但因为我买了一台新电脑,并且在macOS上有最新版本的R,它提到某些包不适用于这个版本的R。
我试着直接在R studio上下载R,结果给了我一些错误。
接下来,我尝试使用以下命令直接从GitHUB安装:

install.packages('raster', repos='https://rspatial.r-universe.dev')

这是我收到的错误信息:

Installing package into ‘/Users/username/Library/R/arm64/4.2/library’
(as ‘lib’ is unspecified)
also installing the dependency ‘terra’

Packages which are only available in source form, and may need compilation of
  C/C++/Fortran: ‘terra’ ‘raster’
Do you want to attempt to install these from sources? (Yes/no/cancel) yes
installing the source packages ‘terra’, ‘raster’

trying URL 'https://rspatial.r-universe.dev/src/contrib/terra_1.6-43.tar.gz'
Content type 'application/x-gzip' length 1777090 bytes (1.7 MB)
==================================================
downloaded 1.7 MB

trying URL 'https://rspatial.r-universe.dev/src/contrib/raster_3.6-6.tar.gz'
Content type 'application/x-gzip' length 1310884 bytes (1.3 MB)
==================================================
downloaded 1.3 MB

* installing *source* package ‘terra’ ...
** using staged installation
configure: CC: clang -arch arm64
configure: CXX: clang++ -arch arm64 -std=gnu++11
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘terra’
* removing ‘/Users/username/Library/R/arm64/4.2/library/terra’
Warning in install.packages :
  installation of package ‘terra’ had non-zero exit status
ERROR: dependency ‘terra’ is not available for package ‘raster’
* removing ‘/Users/username/Library/R/arm64/4.2/library/raster’
Warning in install.packages :
  installation of package ‘raster’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/zp/vysqcnr95g5d08jhlmzrvj9m0000gn/T/Rtmpn4J6eA/downloaded_packages’

当我接下来加载光栅时,这是我看到的:

library(raster)
#Error: package or namespace load failed for ‘raster’ in #loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
# there is no package called ‘terra’

当我尝试安装Terra时,这是我看到的错误消息:

> install.packages('terra')
Installing package into ‘/Users/sofigreen/Library/R/arm64/4.2/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.2/terra_1.6-41.tgz'
Content type 'application/x-gzip' length 99009623 bytes (94.4 MB)
===============
downloaded 28.7 MB

Warning in install.packages :
  downloaded length 30079735 != reported length 99009623
Warning in install.packages :
  URL 'http://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.2/terra_1.6-41.tgz': status was 'Failure when receiving data from the peer'
Error in download.file(url, destfile, method, mode = "wb", ...) : 
  download from 'http://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.2/terra_1.6-41.tgz' failed
Warning in install.packages :
  download of package ‘terra’ failed

当尝试从source下载terra时:

> install.packages('terra', repos='https://rspatial.r-universe.dev')
Installing package into ‘/Users/username/Library/R/arm64/4.2/library’
(as ‘lib’ is unspecified)
Package which is only available in source form, and may need compilation of
  C/C++/Fortran: ‘terra’
Do you want to attempt to install these from sources? (Yes/no/cancel) yes
installing the source package ‘terra’

trying URL 'https://rspatial.r-universe.dev/src/contrib/terra_1.6-43.tar.gz'
Content type 'application/x-gzip' length 1786823 bytes (1.7 MB)
==================================================
downloaded 1.7 MB

* installing *source* package ‘terra’ ...
** using staged installation
configure: CC: clang -arch arm64
configure: CXX: clang++ -arch arm64 -std=gnu++11
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘terra’
* removing ‘/Users/username/Library/R/arm64/4.2/library/terra’
Warning in install.packages :
  installation of package ‘terra’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/zp/vysqcnr95g5d08jhlmzrvj9m0000gn/T/RtmpfniygU/downloaded_packages’

我真的需要光栅包。请帮帮我

yb3bgrhw

yb3bgrhw1#

确保您的系统上安装了Rtoolsclick here)。然后尝试以下步骤:
1-打开RStudio时,右键单击图标并选择`以管理员身份运行。
2-暂时停用防火墙或防病毒软件。
3-使用以下命令:

install.packages('raster', dependencies=TRUE, repos='https://CRAN.R-project.org/')
library(raster)

看看问题是否解决了。

vatpfxk5

vatpfxk52#

你能编辑你的问题并显示你运行时会发生什么吗

install.packages('terra')
install.packages('raster')

我不会从源代码安装,如果你不需要。但是如果你一定要,首先安装“terra”。有关从源代码安装的说明,请参阅https://github.com/rspatial/terra

相关问题