gpt4 book ai didi

R:从终端安装包时出错

转载 作者:行者123 更新时间:2023-12-02 00:03:15 28 4
gpt4 key购买 nike

我正在尝试使用 shell 命令在 R 中安装一些包。我写了一个 R 文件“installDependencies.R”来安装包。文件如下:

packages <- c("xts","stringr","log4r")

# Function to check whether package is installed
is.installed <- function(mypkg){
is.element(mypkg, installed.packages()[,1])
}

for(package in packages){
# check if package is installed
if (!is.installed(package)){
install.packages(package)
}
}

现在我尝试使用终端运行这个文件。我创建了一个 shell 脚本文件 inst.sh 如下:

#!/bin/bash

Rscript installDependencies.R

每当我使用 ./inst.sh 命令运行文件时,都会生成以下错误:

algotree@algotree-900X3C-900X4C-900X4D:~$ ./inst.sh
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in contrib.url(repos, type) :
trying to use CRAN without setting a mirror
Calls: install.packages -> grep -> contrib.url
Execution halted
algotree@algotree-900X3C-900X4C-900X4D:~$

最佳答案

我在设置 CRAN 镜像之前遇到了类似的问题

for(x in pkgs){
if(!is.element(x, installed.packages()[,1]))
{install.packages(x, repos="http://cran.fhcrc.org")
} else {print(paste(x, " library already installed"))}
}

关于R:从终端安装包时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064920/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com