服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - R语言 - Rstudio中安装package出现的问题及解决

Rstudio中安装package出现的问题及解决

2022-01-05 16:20LiuHuan_study R语言

这篇文章主要介绍了Rstudio中安装package出现的问题及解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

Rstudio中安装package问题

一、 install.packages('REmap')无法安装package:错误:“无法与服务器建立连接”

解决方式:切换下载的镜像

方法一:在Rstudio菜单栏:tools-global options-packages中切换下载的镜像

Rstudio中安装package出现的问题及解决

方法二:修改文件,在安装文件夹中找到Rprofile.site文件,我的路径是D:\Program Files\R\R-3.4.1\etc,用记事本打开,在里面添加语句:

# set a CRAN mirror
local({r <- getOption(“repos”)
r[“CRAN”] <- “http://mirrors.tuna.tsinghua.edu.cn/CRAN/”
options(repos=r)}

 

二、手动安装package

在网站:https://mirrors.tuna.tsinghua.edu.cn/CRAN/下载好需要的package

1.在R studio下,选择packages

Rstudio中安装package出现的问题及解决

2.选择Install

3.Install from栏选择Package Archive File(.zip;.tar.gz)

Rstudio中安装package出现的问题及解决

4.Package archive栏点击Browser,选择刚才下载的文件

5.点击Install,进行安装

致此,手动安装R包完成。安装提示如下

推荐第一种安装方式:因为第一种安装方式会自动安装依赖的包,而第二种方式,除了下载你想安装的包还要下载所有依赖的包,这就有一定的难度了。

补充:Rstudio安装packages时报错,原因可能是这样

最近接触R语言,安装好Rstudio后,需要安装R的第三方包mirt。

 

执行步骤如下:

Rstudio中安装package出现的问题及解决

Rstudio中安装package出现的问题及解决

正当满心欢喜地期待包的安装时,结果出现了下面的情况:

install.packages("mirt")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/likailei/Documents/R/win-library/3.6'
(as ‘lib' is unspecified)
Warning in install.packages :
unable to access index for repository https://cran.rstudio.com/src/contrib:
cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
package ‘mirt' is not available (for R version 3.6.0)
Warning in install.packages :
unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.6:
cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/PACKAGES'

什么鬼?!

此处省略5000字的辛苦排错的历程描述,直接贴上解决方案:

Rstudio默认使用的国外镜像源,国内无法正常访问。

Rstudio设置如下

Tools>global options>packages

Rstudio中安装package出现的问题及解决

更改镜像源后,重新执行安装操作。

install.packages("mirt")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/likailei/Documents/R/win-library/3.6'
(as ‘lib' is unspecified)
also installing the dependencies ‘permute', ‘GPArotation', ‘Rcpp', ‘vegan', ‘Deriv', ‘dcurver', ‘RcppArmadillo'

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/permute_0.9-5.zip'
Content type 'application/zip' length 505181 bytes (493 KB)
downloaded 493 KB

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/GPArotation_2014.11-1.zip'
Content type 'application/zip' length 162104 bytes (158 KB)
downloaded 158 KB

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/Rcpp_1.0.1.zip'
Content type 'application/zip' length 4494896 bytes (4.3 MB)
downloaded 4.3 MB

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/vegan_2.5-5.zip'
Content type 'application/zip' length 3861520 bytes (3.7 MB)
downloaded 3.7 MB

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/Deriv_3.8.5.zip'
Content type 'application/zip' length 133828 bytes (130 KB)
downloaded 130 KB

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/dcurver_0.9.1.zip'
Content type 'application/zip' length 639915 bytes (624 KB)
downloaded 624 KB

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/RcppArmadillo_0.9.400.3.0.zip'
Content type 'application/zip' length 2276463 bytes (2.2 MB)
downloaded 2.2 MB

trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/mirt_1.30.zip'
Content type 'application/zip' length 2572772 bytes (2.5 MB)
downloaded 2.5 MB

package ‘permute' successfully unpacked and MD5 sums checked
package ‘GPArotation' successfully unpacked and MD5 sums checked
package ‘Rcpp' successfully unpacked and MD5 sums checked
package ‘vegan' successfully unpacked and MD5 sums checked
package ‘Deriv' successfully unpacked and MD5 sums checked
package ‘dcurver' successfully unpacked and MD5 sums checked
package ‘RcppArmadillo' successfully unpacked and MD5 sums checked
package ‘mirt' successfully unpacked and MD5 sums checked

完美!!!

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。

原文链接:https://blog.csdn.net/LiuHuan_study/article/details/85778047

延伸 · 阅读

精彩推荐
  • R语言R语言中c()函数与paste()函数的区别说明

    R语言中c()函数与paste()函数的区别说明

    这篇文章主要介绍了R语言中c()函数与paste()函数的区别说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    yiyu_j11152022-01-12
  • R语言聊聊R语言中Legend 函数的参数用法

    聊聊R语言中Legend 函数的参数用法

    这篇文章主要介绍了聊聊R语言中Legend 函数的参数用法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    Gavin姓陈6352021-12-28
  • R语言R语言可视化存储矢量图实现方式

    R语言可视化存储矢量图实现方式

    这篇文章主要为大家介绍了R语言存储矢量图的实现方式过程,有需要的朋友可以借鉴参考下,希望能够有所你帮助,祝大家多多进步,早日升职加薪...

    Kanny广小隶9392022-01-20
  • R语言R语言创建矩阵的实现方法

    R语言创建矩阵的实现方法

    这篇文章主要介绍了R语言创建矩阵的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随...

    hjk_caesar9462021-12-27
  • R语言R studio 批量注释的快捷方式

    R studio 批量注释的快捷方式

    这篇文章主要介绍了R studio 批量注释的快捷方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    JasonKQLin13342022-01-04
  • R语言R语言-使用ifelse进行数据分组

    R语言-使用ifelse进行数据分组

    这篇文章主要介绍了R语言-使用ifelse进行数据分组,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    小力丸12042022-01-10
  • R语言R语言编程学习绘制动态图实现示例

    R语言编程学习绘制动态图实现示例

    这篇文章主要介绍了R语言编程学习绘制动态图实现示例,有需要的的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪...

    微小冷7652022-01-18
  • R语言R语言绘制散点图实例分析

    R语言绘制散点图实例分析

    在本篇文章里小编给大家整理的是一篇关于R语言绘制散点图实例分析内容,有需要的朋友们可以学习下。...

    w3cschool6942022-01-06