如何获得 drake 目标在磁盘上占用的大小?
How can I get the size that a drake target takes on disk?
当需要了解我的drake计划时,vis_drake_graph()
就派上用场了,它显示了每个目标到运行所花费的时间。这对于确定是否应分解目标以减少小更改的重新运行时间非常有帮助。
我的需求是相关的:因为我的许多long-运行ning目标涉及大型数据集的操作,所以了解每个缓存目标占用的大小对我来说很重要在磁盘上 。这将帮助我理解是否应合并目标以防止存储大量中间结果(即使在更改合并目标的情况下会增加重新运行时间)。
检查 drake_graph_info()
返回的配置对象和中间对象,我未能找到此信息。我在想,通过为 vis_drake_graph()
指定参数或什至仅通过检查配置来显示此信息和可能的其他信息(例如目标上次 运行 的时间)可能非常有用手动对象。
那么问题来了,有没有办法获取这些信息?
drake
uses a package called storr
to handle the storage of targets. As far as I know, storr
does not have an easy way to get file size information. However, at least for the default storr_rds()
cache type, maybe it should. You could request it as a feature。如果实施,我们将有以下解决方法的更简单版本,至少在 RDS 缓存的情况下。
library(drake)
load_mtcars_example()
make(my_plan, verbose = 0L)
cache <- get_cache() # or storr::storr_rds(".drake")
root <- cache$driver$path
hash <- cache$driver$get_hash("small", namespace = "objects")
path <- file.path(root, "data", paste0(hash, ".rds"))
file.exists(path)
#> [1] TRUE
file.size(path)
#> [1] 404
由 reprex package (v0.2.1)
于 2019-05-07 创建
drake
is all about repetition and runtime, and storr
都是关于数据和存储的。当我们考虑新功能时,我更愿意将这些单独的目标牢记在心。
感谢@landau 的回答,使用此信息我实现了一个报告目标大小的函数,允许快速检查计划中所有目标的大小:
library(tibble)
library(drake)
get_target_size <- function(target) {
cache <- get_cache() # or storr::storr_rds(".drake")
root <- cache$driver$path
hash <- cache$driver$get_hash(target, namespace = "objects")
path <- file.path(root, "data", paste0(hash, ".rds"))
if ( file.exists(path) ) {
file.size(path)
} else {
NA
}
}
load_mtcars_example()
make(my_plan, verbose = 0L)
tibble( target = my_plan$target,
size = sapply(my_plan$target, get_target_size))
输出为:
# A tibble: 15 x 2
target size
<chr> <dbl>
1 report 55
2 small 404
3 large 463
4 regression1_small 2241
...
我认为这足以满足我的需求,并且理解将其作为 drake 的一部分来实现可能没有意义,除非有适用于任何存储类型的更通用的解决方案。
当需要了解我的drake计划时,vis_drake_graph()
就派上用场了,它显示了每个目标到运行所花费的时间。这对于确定是否应分解目标以减少小更改的重新运行时间非常有帮助。
我的需求是相关的:因为我的许多long-运行ning目标涉及大型数据集的操作,所以了解每个缓存目标占用的大小对我来说很重要在磁盘上 。这将帮助我理解是否应合并目标以防止存储大量中间结果(即使在更改合并目标的情况下会增加重新运行时间)。
检查 drake_graph_info()
返回的配置对象和中间对象,我未能找到此信息。我在想,通过为 vis_drake_graph()
指定参数或什至仅通过检查配置来显示此信息和可能的其他信息(例如目标上次 运行 的时间)可能非常有用手动对象。
那么问题来了,有没有办法获取这些信息?
drake
uses a package called storr
to handle the storage of targets. As far as I know, storr
does not have an easy way to get file size information. However, at least for the default storr_rds()
cache type, maybe it should. You could request it as a feature。如果实施,我们将有以下解决方法的更简单版本,至少在 RDS 缓存的情况下。
library(drake)
load_mtcars_example()
make(my_plan, verbose = 0L)
cache <- get_cache() # or storr::storr_rds(".drake")
root <- cache$driver$path
hash <- cache$driver$get_hash("small", namespace = "objects")
path <- file.path(root, "data", paste0(hash, ".rds"))
file.exists(path)
#> [1] TRUE
file.size(path)
#> [1] 404
由 reprex package (v0.2.1)
于 2019-05-07 创建drake
is all about repetition and runtime, and storr
都是关于数据和存储的。当我们考虑新功能时,我更愿意将这些单独的目标牢记在心。
感谢@landau 的回答,使用此信息我实现了一个报告目标大小的函数,允许快速检查计划中所有目标的大小:
library(tibble)
library(drake)
get_target_size <- function(target) {
cache <- get_cache() # or storr::storr_rds(".drake")
root <- cache$driver$path
hash <- cache$driver$get_hash(target, namespace = "objects")
path <- file.path(root, "data", paste0(hash, ".rds"))
if ( file.exists(path) ) {
file.size(path)
} else {
NA
}
}
load_mtcars_example()
make(my_plan, verbose = 0L)
tibble( target = my_plan$target,
size = sapply(my_plan$target, get_target_size))
输出为:
# A tibble: 15 x 2
target size
<chr> <dbl>
1 report 55
2 small 404
3 large 463
4 regression1_small 2241
...
我认为这足以满足我的需求,并且理解将其作为 drake 的一部分来实现可能没有意义,除非有适用于任何存储类型的更通用的解决方案。