Skip to content

Commit 4051227

Browse files
committed
allow custom output html name via the "path" argument; ignore from r build pkgdown directory
1 parent 9b69dbe commit 4051227

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
materials*
44
^docs$
55
^_pkgdown\.yml$
6+
^pkgdown$
67
^\.travis\.yml$
78
^cran-comments\.md$
89
^doc$

R/explain_forest.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
#' Explains a random forest in a html document using plots created by randomForestExplainer
44
#'
55
#' @param forest A randomForest object created with the option localImp = TRUE
6+
#' @param path Path to write output html to
67
#' @param interactions Logical value: should variable interactions be considered (this may be time-consuming)
78
#' @param data The data frame on which forest was trained - necessary if interactions = TRUE
89
#' @param vars A character vector with variables with respect to which interactions will be considered if NULL then they will be selected using the important_variables() function
910
#' @param no_of_pred_plots The number of most frequent interactions of numeric variables to plot predictions for
1011
#' @param pred_grid The number of points on the grid of plot_predict_interaction (decrease in case memory problems)
1112
#' @param measures A character vector specifying the importance measures to be used for plotting ggpairs
1213
#'
13-
#' @return A html document in your working directory
14+
#' @return A html document. If path is not specified, this document will be "Your_forest_explained.html" in your working directory
1415
#'
1516
#' @import DT
1617
#'
@@ -21,8 +22,12 @@
2122
#' }
2223
#'
2324
#' @export
24-
explain_forest <- function(forest, interactions = FALSE, data = NULL, vars = NULL, no_of_pred_plots = 3, pred_grid = 100,
25+
explain_forest <- function(forest, path = NULL, interactions = FALSE, data = NULL, vars = NULL, no_of_pred_plots = 3, pred_grid = 100,
2526
measures = NULL){
27+
if(is.null(path)) {
28+
directory <- getwd()
29+
paste0(directory, "/Your_forest_explained.html")
30+
}
2631
if(is.null(measures)){
2732
if("randomForest" %in% class(forest)){
2833
if(forest$type %in% c("classification", "unsupervised")){
@@ -53,12 +58,12 @@ explain_forest <- function(forest, interactions = FALSE, data = NULL, vars = NUL
5358
environment$no_of_pred_plots <- no_of_pred_plots
5459
environment$pred_grid <- pred_grid
5560
environment$measures <- measures
56-
directory <- getwd()
61+
5762
path_to_templates <- file.path(path.package("randomForestExplainer"), "templates")
5863
template_name <- grep('explain_forest_template.rmd', list.files(path_to_templates),
5964
ignore.case = TRUE, value = TRUE)
6065

6166
rmarkdown::render(file.path(path_to_templates, template_name),
62-
"html_document", output_file = paste0(directory, "/Your_forest_explained.html"),
67+
"html_document", output_file = path,
6368
envir = environment)
6469
}

man/explain_forest.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)