r - 尝试安装软件包时 contrib.url(repos, "Source) 中的 R 错误,但未指定 repo
问题描述
大家好,我在 R 中工作,试图使用 RMarkdown 运行一些代码,这是似乎给我带来问题的代码片段。
install.packages("car")
install.packages("bestNormalize")
library(readr)
library(dplyr)
library(leaps)
library(MASS)
library(car)
library(plyr)
library(alr4)
它很标准的东西。尝试运行代码时收到以下错误。
Error in contrib.url(repos, "source"):trying to use CRAN without setting a mirror Calls:
<Anonymous> ... withVisible
-> eval -> eval -> install.packages -> contrib.url Execution halted
我最近购买了一台新笔记本电脑并安装了 R。在我的旧笔记本电脑中,当我指定 install("package_name") 时,我从未收到此错误。发生这种情况是否有原因?我已经看到建议的解决方案以下列方式指定 repo:
install.packages("car", repos="http://cran.us.r-project.org")
但是我不满足于这个解决方案,因为我不想在每次尝试安装软件包时都指定存储库。我想也许找到某种方法将镜像设置为默认镜像,但不知道是否可以这样做。有任何想法吗?
解决方案
我找到了解决方案。我做了以下事情:我通过运行以下命令找到并打开了我的 .RProfile:
file.edit(file.path("~", ".Rprofile"))
然后我导航到https://cran.r-project.org并找到离我最近的镜子。然后在 .Rprofile 我写了以下命令,以便让 R studio 在打开时确认我的偏好
options(repos=structure(c(CRAN="https:theclosest_mirror_to_yourlocation.com")))
将其保存到 .Rprofile 并运行初始代码表明它是成功的。
推荐阅读
- java - 基于输入在java中动态创建对象类
- java - Spring Boot 自动配置和属性
- javascript - 如何从具有匿名函数的 div 中删除事件侦听器
- python-3.x - 如何在python中多拆分列
- spring - 我无法在 Jpa 单元测试中从 H2 获取我的数据
- node.js - `Extensions` 字段未显示在 apollo graphql 响应数据中
- python - 尽管训练是 100%,但无法提高验证准确度以及如何将从视频中提取的图像提供给深度学习模型
- datepicker - 在 datePicker 中禁用手动输入日期
- javascript - 我应该避免使用 px 使 react-app 移动友好吗?
- php - 我需要向我的动态数据表添加超链接