我是 RStudio 的新用户,在使用 .rmd 文件和 Knit HTML 时遇到错误
如果我有 install.packages 行:
install.packages('ggplot2');
library(ggplot2);
当我单击“Knit HTML”时,返回错误:
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror calls: ... withVisible -> eval -> eval -> install.packages -> contrib.url Execution halted
我可以使用以下方法解决这个问题:
if (!require('ggplot2'))
{
install.packages('ggplot2');
library(ggplot2);
}
如果我正在编写 .rmd,每次安装新软件包时是否都需要使用 if (!require(
行?) 有没有办法避免这种情况,以便我可以编写仅install.packages(
?
最佳答案
您不需要每次都使用 install.package()
行。
通常,您应该在控制台或单独的交互式 session 中安装软件包,或者在安装该库后删除该行(此处为 ggplot)。
只需使用库(ggplot2)
library(ggplot2);
希望对你有帮助
关于r - 错误 R Studio Knit HTML 与 install.packages 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30959839/