当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R hardhat refresh_blueprint 刷新预处理蓝图


refresh_blueprint() 是面向开发人员的通用函数,在 update_blueprint() 末尾调用。它只是特定于方法的 new_*_blueprint() 函数的包装,该函数再次通过构造函数运行更新后的蓝图,以确保蓝图的所有元素在更新后仍然有效。

用法

refresh_blueprint(blueprint)

参数

blueprint

预处理蓝图。

blueprint 在调用相应的构造函数后返回。

细节

如果您实现自己的自定义 blueprint ,则应导出 refresh_blueprint() 方法,该方法仅调用蓝图的构造函数,并将蓝图的所有元素传递给构造函数。

例子


blueprint <- default_xy_blueprint()

# This should never be done manually, but is essentially
# what `update_blueprint(blueprint, intercept = TRUE)` does for you
blueprint$intercept <- TRUE

# Then update_blueprint() will call refresh_blueprint()
# to ensure that the structure is correct
refresh_blueprint(blueprint)
#> XY blueprint: 
#>  
#> # Predictors: 0 
#>   # Outcomes: 0 
#>    Intercept: TRUE 
#> Novel Levels: FALSE 
#>  Composition: tibble 

# So you can't do something like...
blueprint_bad <- blueprint
blueprint_bad$intercept <- 1

# ...because the constructor will catch it
try(refresh_blueprint(blueprint_bad))
#> Error in new_blueprint(intercept = intercept, allow_novel_levels = allow_novel_levels,  : 
#>   `intercept` must be `TRUE` or `FALSE`, not the number 1.

# And update_blueprint() catches this automatically
try(update_blueprint(blueprint, intercept = 1))
#> Error in new_blueprint(intercept = intercept, allow_novel_levels = allow_novel_levels,  : 
#>   `intercept` must be `TRUE` or `FALSE`, not the number 1.
源代码:R/blueprint.R

相关用法


注:本文由纯净天空筛选整理自Davis Vaughan等大神的英文原创作品 Refresh a preprocessing blueprint。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。