r - 无法在 R 中安装 "raster"包

标签 r package raster

我正在尝试在 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

当尝试从源下载 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’

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

最佳答案

确保您的系统上安装了Rtools ( click here )。然后尝试以下步骤:

1- 打开 RStudio 时,右键单击该图标并选择“以管理员身份运行”。

2- 暂时停用您的防火墙或防病毒软件。

3-使用以下命令:

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

看看问题是否解决。

关于r - 无法在 R 中安装 "raster"包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74482465/

相关文章:

r - gsub 并返回字符串中的正确数字

python - 如何直接运行Python包的主脚本?

r - 绘制整个栅格堆栈时添加栅格值

r - 使用 R 转换为 NetCDF 时保留栅格变量名称

r - 将负二项式模型预测为具有偏移项的栅格

r - 如何在树状图中提取具有高度的某个节点下的标签?

R: kable_as_image 找不到 Ghostscript

r - 从数据框中仅选择数字列

javascript - 打印所有已安装的 node.js 模块的列表

Java - 找不到符号类并发