當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。