我无法安装预测包

I cant install the forecast package

我已经安装了最新版本的 R,但我无法安装软件包 forecast。当我尝试时,出现错误:

No such file or directory Error in install.packages : cannot open the connection

以下可能有用:

在我看来,您需要更改 RStudio 中的 CRAN 访问机制。我不确定 OS 你在 运行 RStudio 上,所以这里是 OS 的细目分类。我在 Centos 7 上遇到了同样的问题,我就是这样解决的。

Windows

utils::setInternet2(TRUE)
options(download.file.method = "internal")

请注意,setInternet2(TRUE) 是 RStudio 中的默认值,但不适用于 R GUI。如果您不想在 Windows 上使用 setInternet2(TRUE),那么配置安全下载的唯一其他方法是在您的 PATH 上安装 “wget”“curl” 实用程序,如OS X 和 Linux 下面。

OS X

options(download.file.method = "curl")

Linux

options(download.file.method = "wget")

请注意,“curl”“wget” 方法可以在任何平台上运行,只要必要的二进制文件在系统 PATH 中即可。上述建议基于以下事实:“curl”包含在 OS X 中,而 “wget” 包含在大多数 Linux 发行版中。

建议的解决方案

我在 Centos 7 上使用它来重新配置我的 CRAN 设置。我已将此添加到我的 .Rprofile,您可以在 R 提示符下按 运行 尝试。

options(download.file.method = "wget") # <- for MacOSX use curl

local({
     r<- getOption("repos");
     r["CRAN"] <-"https://cran.rstudio.com/"
     options(repos=r)
}) 

> install.packages("forecast")

解释:

当 R 通过 HTTP 传输文件时(例如使用 install.packages 或 download.file 函数),根据 download.file.method 选项选择下载方法。有几种方法可用,如果没有明确指定选项,默认行为是使用 R 的内部 HTTP 实现。在许多情况下,此内部方法不支持 HTTPS 连接,因此您需要覆盖默认值。

参考:https://support.rstudio.com/hc/en-us/articles/206827897-Secure-Package-Downloads-for-R