gpt4 book ai didi

r - .Rprofile 中的动态列大小调整

转载 作者:行者123 更新时间:2023-12-04 09:42:57 25 4
gpt4 key购买 nike

我想在我的 .Rprofile 中加入以下内容:

# auto width adjustment
.adjustWidth <- function(...){
options(width=Sys.getenv("COLUMNS"))
TRUE
}
.adjustWidthCallBack <- addTaskCallback(.adjustWidth)

这将动态地将 R session 中的最大列的大小调整为窗口的宽度。这适用于交互式 session ,但是在执行 R CMD INSTALL 或批处理 session 之类的操作时,我总是得到:
Error in options(width = Sys.getenv("COLUMNS")) : 
invalid 'width' parameter, allowed 10...10000
Execution halted

我怎样才能解决这个问题?我认为问题是 Sys.getenv("COLUMNS") 以某种方式失败了?是否有一些 if() 语句可以让我检测我是否批量运行?原来的自动宽度调整代码不是我的,我在网上的其他地方找到的。

最佳答案

也许将选项包装在 try 中功能帮助:

try( options(width=Sys.getenv("COLUMNS")), silent = TRUE)

关于r - .Rprofile 中的动态列大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7725152/

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