R问题:包

找不到包,或R版本太新的问题

  • "package ‘tswge’ is not available (for R version xxx)"
    install.packages('tswge', repos="http://cran.rstudio.org")
  • "warning: package ‘tswge’ was built under R version xxx"

警告信息,可以忽略,能使用。如果R升级了就不会出现警告
(换成上面的repository也能解决问题)

  • "Error: package or namespace load failed for ‘stats’ in inDL(x, as.logical(local), as.logical(now), ...)"

路径设置的问题!查询Windows系统路径有没有包含.\R\bin\x64.\R\bin\i386,没有就说明R不在系统路径!右键“我的电脑->属性->环境变量->所有用户->PATH->编辑”,加上R路径!
如果用过Rtools,%USERPROFILE%\documents中就有.Renviron,设定了R的查找路径(R的系统路径),是Windows系统路径的增强或扩展。将.Renviron改名或删除或移出%USERPROFILE%\documents即可。(以后要用Rtools再设置)

安装github上的包

使用devtools::install_github需要已经安装了Rtools。

devtools::install_github

使用{devtools}中的install_github,需要知道开发者的名字,需要安装{Rtools}。使用方式

install_github("DeveloperName/PackageName")

比如从github安装"dplyr"

library(devtools)
install_github("hadley/dplyr")

githubinstall::githubinstall

使用{githubinstall}包中的函数githubinstall,不需要知道开发者的名字,支持模糊包名,使用方式

githubinstall("packagename")

安装{githubinstall}

install.packages("githubinstall")
## 或直接从github安装
library(devtools)
devtools::install_github("hoxo-m//githubinstall")

然后就能从github安装某些包。比如从github安装"dplyr"

library(githubinstall)
githubinstall("dplyr")

但是有问题了:

Error in curl::curl_download(input, tmpFile, mode = "wb", quiet = !showProgress) :
Could not resolve host: raw.githubusercontent.com

安装Rtools

在(https://cran.r-project.org/bin/windows/Rtools/)下载安装Rtools,配置路径使用下述之一:(其中D:\\rtools40是Rtools的安装目录)

  • 在系统路径中添加Rtools路径
  • %USERPROFILE%\Documents编辑.Renviron文件,内容为
    PATH="D:\\rtools40\\usr\\bin\\usr\\bin;%PATH%"
  • 在R中运行如下命令
    writeLines('PATH="D:\\rtools40\\usr\\bin;%PATH%"', con = "~/.Renviron")
  • (重新)启动R,运行函数
Sys.which("make")
## D:\\rtools40\\usr\\bin\\make.exe

然后试着编译如下的包

install.packages("jsonlite",type="source")

查看R给出的编译信息,确认已经成功安装了Rtools。

几个国内镜像:

清华:https://mirrors.tuna.tsinghua.edu.cn/CRAN/
中科大:https://mirrors.ustc.edu.cn/CRAN/
兰州大学:https://mirror.lzu.edu.cn/CRAN/
同济大学:https://mirrors.tongji.edu.cn/CRAN/

参考文献

  1. A Helpful Way to Install R Packages Hosted on GitHub
  2. Using Rtools40 on Windows
posted @   hzworld  阅读(1088)  评论(4编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
点击右上角即可分享
微信分享提示