JeffreyRacine / R-Package-np

R package np (Nonparametric Kernel Smoothing Methods for Mixed Data Types)
https://socialsciences.mcmaster.ca/people/racinej
47 stars 18 forks source link

Add verbose flag to skip "Multistart i of n"? #25

Closed egarpor closed 4 years ago

egarpor commented 4 years ago

First, many thanks Jeff for your package, I think it is amazing! What it comes next is meant to be a suggestion.

The "Multistart %d of %d %c" feature that is present in many np functions is very useful to keep track of the execution in regular R sessions. However, it can be cumbersome when dealing with R markdown documents. This is because it seems to be no verbose flag to deactivate the messages neither they are removed via suppressMessages.

Therefore, an R Markdown chunk like this

```{r, message = FALSE}
# Dummy data
X <- rnorm(50)
Y <- 1 + 2 * X + rnorm(50, sd = 0.1)

# Lots of screen outputs
bw1 <- np::npregbw(formula = Y ~ X)
suppressMessages(bw2 <- np::npregbw(formula = Y ~ X))

# Removing screen information
a <- capture.output(bw3 <- np::npregbw(formula = Y ~ X))
```

results in

# Dummy data
X <- rnorm(50)
Y <- 1 + 2 * X + rnorm(50, sd = 0.1)

# Lots of screen outputs
bw1 <- np::npregbw(formula = Y ~ X)
## 
Multistart 1 of 1 |
Multistart 1 of 1 |
Multistart 1 of 1 |
Multistart 1 of 1 /
Multistart 1 of 1 |
Multistart 1 of 1 |

suppressMessages(bw2 <- np::npregbw(formula = Y ~ X))
## 
Multistart 1 of 1 |
Multistart 1 of 1 |
Multistart 1 of 1 |
Multistart 1 of 1 /
Multistart 1 of 1 |
Multistart 1 of 1 |

# Removing screen information
a <- capture.output(bw3 <- np::npregbw(formula = Y ~ X))

which is not very nice for producing a pdf document (and especially if the number of multistarts is larger).

In my view, two alternative possibilities for improving the np +knitr experience could be:

The workaround based on capture.output exposed above works, but that has an impact on the readability of the code.

JeffreyRacine commented 4 years ago

Greetings,

Thanks for the kind words. The following is what you are looking for...

options(np.messages=FALSE)

Thanks!

egarpor commented 4 years ago

Many thanks! I completely missed that feature... Glad to know about it!