循环和如果语句检查和加载软件包
为什么不需要包装载体?还可以将PKG拆分用于install.package和Biocmanager吗?因此,如果软件包无法与install.package安装,请与Biocmanager核对?
错误: [1]“ stringr” 加载所需的软件包:我 print.default中的错误(“尝试安装”,i): 无效的打印数字-2147483648 另外:警告消息: 1:在库中(package,lib.loc = lib.loc,tarne.only = true,logical.return = true,: 没有包装称为“我” 2:在print.default中(“尝试安装”,i):强制引入的NAS
pkg <- c("stringr", "openxlsx")
for (i in pkg){
print(i)
if(require(i)){
print(i, "is loaded correctly")
} else{
print("trying to install", i)
install.packages(i)
if(require(i)){
print(i, "installed and loaded")
} else{
stop("could not install", i)
}
}
}
Why wont require take a vector of packages? Also is there a way to split pkg for both install.package and BiocManager? Thus, if packages fails to install with install.package, check with BiocManager?
Error:
[1] "stringr"
Loading required package: i
Error in print.default("trying to install", i) :
invalid printing digits -2147483648
In addition: Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘i’
2: In print.default("trying to install", i) : NAs introduced by coercion
pkg <- c("stringr", "openxlsx")
for (i in pkg){
print(i)
if(require(i)){
print(i, "is loaded correctly")
} else{
print("trying to install", i)
install.packages(i)
if(require(i)){
print(i, "installed and loaded")
} else{
stop("could not install", i)
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在循环中至少是3个错误。首先,第一个
的缺少参数需要
...代码> i 可以评估而不是作为软件包名称,(请参阅
?quired
参数部分)...最后,未能在
中连接所需的字符值打印
用粘贴
调用。 (请参阅?print.default
的参数部分。打印功能仅打印其第一个参数。其第二个参数是数字数,如控制台错误消息所述。)我确实收到了:”警告消息:
在库中(package,lib.loc = lib.loc,tarne.only = true,logical.return = true,:
我不理解该循环的第一次运行后没有称为'OpenXlsx'的软件包(因为消息
[1]“ OpenXLSX已安装和加载”
已打印,并且包装确实安装了软件包可以加载。信息。There
arewere at least 3 errors in thatfor
loop. First, a missing argument to the firstrequire
,... then failing to set the
character.only
argument forrequire
to TRUE so thati
can get evaluated rather than taken as a package name, (see?require
Arguments section)... and finally, failing to join the desired character values in the
print
calls withpaste
. (See?print.default
's Argument section. The print function only prints its first argument. Its second argument is the number of digits, as stated by the console error message.)I did get : "Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘openxlsx’" after the first run of that loop which I do not understand (since the message
[1] "openxlsx installed and loaded"
was printed, and the package did get installed and could be loaded. I'm guessing it had something to do with these activities being done within a function and there was some mismatch of environments??? When I removed pkg:openxlsx and re-ran my code I do not get the warning message.