R for循环中更详细的进度条
R More detailed progress bars in for loops
我正在为我的一些循环播放进度条。
在我写的循环之外:
total = length(df$x)
pb <- winProgressBar(title = "Progress Bar", min = 0, max =total , width = 300)
然后在关闭循环之前我有:
setWinProgressBar(pb, i, title=paste( round(which(df$x== i)/total*100, 0),"% done"))
这给了我一个更新百分比的进度条。然而,酒吧根本没有填满。我希望栏 space 填充(如果我们有选择,最好是蓝色)。我需要添加什么?我还想添加一个剩余时间元素,就像在 pbapply 中一样。
另一方面,更复杂的注意事项,当然,一个不足之处是每个 i 在 size/length 中可能不相等,因此理论上的进度条不会告诉您您需要知道的关于时间的所有信息可能会被带走。
有什么方法可以在我的循环中构建,以便我们首先扫描所有 i 然后进度条根据该分布工作,而不是假设它是统一的?在我现在使用的循环中,每个 i 都是一个转换为 data.frame 的文件。文件大小或数据框中行的长度将是很好的衡量标准。
填充栏的自学答案。读取文件的循环示例:
df <- data.frame(x=(list.files("new/")))
total = length(df$x)
pb <- winProgressBar(title = "Progress Bar", label="0% done", min = 0, max =total , width = 300, initial=0)
for(i in df$x){
u <- fread(paste0("Z:/sec/new/",i))
setWinProgressBar(pb, which(df$x== i),label=paste( round(which(df$x== i)/total*100, 0),"% done"))
}
close(pb)
第一次扫描的时间和文件大小我还没想好。
我正在为我的一些循环播放进度条。
在我写的循环之外:
total = length(df$x)
pb <- winProgressBar(title = "Progress Bar", min = 0, max =total , width = 300)
然后在关闭循环之前我有:
setWinProgressBar(pb, i, title=paste( round(which(df$x== i)/total*100, 0),"% done"))
这给了我一个更新百分比的进度条。然而,酒吧根本没有填满。我希望栏 space 填充(如果我们有选择,最好是蓝色)。我需要添加什么?我还想添加一个剩余时间元素,就像在 pbapply 中一样。
另一方面,更复杂的注意事项,当然,一个不足之处是每个 i 在 size/length 中可能不相等,因此理论上的进度条不会告诉您您需要知道的关于时间的所有信息可能会被带走。
有什么方法可以在我的循环中构建,以便我们首先扫描所有 i 然后进度条根据该分布工作,而不是假设它是统一的?在我现在使用的循环中,每个 i 都是一个转换为 data.frame 的文件。文件大小或数据框中行的长度将是很好的衡量标准。
填充栏的自学答案。读取文件的循环示例:
df <- data.frame(x=(list.files("new/")))
total = length(df$x)
pb <- winProgressBar(title = "Progress Bar", label="0% done", min = 0, max =total , width = 300, initial=0)
for(i in df$x){
u <- fread(paste0("Z:/sec/new/",i))
setWinProgressBar(pb, which(df$x== i),label=paste( round(which(df$x== i)/total*100, 0),"% done"))
}
close(pb)
第一次扫描的时间和文件大小我还没想好。