I have the following simple example Rmarkdown document (test.Rmd):
---
title: "Test Knit Caret Paralell VerboseIter"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(caret)
require(doParallel)
```
## data
```{r data}
set.seed(998)
training <- twoClassSim()
```
## model
```{r fitmodel}
fitControl <- trainControl(
method = "repeatedcv",
number = 3,
repeats = 2,
verboseIter = T)
ncores <- detectCores()-1
cl <<- makePSOCKcluster(ncores, verbose = TRUE, outfile = "")
registerDoParallel(cl)
set.seed(825)
Fit <- train(Class ~ .,
data = training,
method = "nnet",
trControl = fitControl,
trace = FALSE
)
stopCluster(cl)
registerDoSEQ()
```
## results
```{r results}
Fit
```
I have several options to run this code or knit the document
Knit button in RstudioKnit document with render("test.Rmd")
The following happens
R markdown panelIn the project I work on I want to knit the document with different parameters, so I want to use the last option. However I also want to see the progress on fitting the model. Therefor I want to use option 3.
How can I get the info of the iterations printed in console when the documents are rendered?
This is the expected output I want to see:
+ Fold1.Rep1: size=1, decay=0e+00
+ Fold1.Rep1: size=3, decay=0e+00
+ Fold1.Rep1: size=5, decay=0e+00
- Fold1.Rep1: size=1, decay=0e+00
+ Fold1.Rep1: size=1, decay=1e-01
- Fold1.Rep1: size=3, decay=0e+00
+ Fold1.Rep1: size=3, decay=1e-01
- Fold1.Rep1: size=5, decay=0e+00
+ Fold1.Rep1: size=5, decay=1e-01
- Fold1.Rep1: size=1, decay=1e-01
+ Fold1.Rep1: size=1, decay=1e-04
- Fold1.Rep1: size=3, decay=1e-01
+ Fold1.Rep1: size=3, decay=1e-04
- Fold1.Rep1: size=1, decay=1e-04
etc.
This may produce what you're looking for, adapted from here, it essentially replicates when you use the knit button in rstudio, which produces the verbose from train, however using this method you should be able to pass in parameters to render. Just change the path to the wd of your rmd file
owd = setwd("path/to/your-Rmd-directory")
system2("Rscript", c("-e", shQuote("library(rmarkdown); render('test.Rmd')"),
system2("html", "test.html"),
setwd(owd)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With