I am attempting to create a vignette in R Markdown for a package that I have created. Within one of these R functions, it has a readline()
requiring user input to confirm continuing an analysis based on certain thresholds. This works in the terminal, as the user can simply answer the question. However, for an R Markdown it automatically spits out a warning. Is there a way to get around this functionality, or to prespecify the user response, or is this not a possibility within R markdown?
I have no issues running in the console, but this will not knit in R markdown. The function asks the user whether to continue and prompts a Yes(1) or No(2) answer. If no, the function stops and prints a warning. If yes, the function continues on. In R Markdown, it automatically spits out the warning.
1
From ?readline
:
In non-interactive use the result is as if the response was RETURN and the value is “”.
So one idea would be to couple interactive()
with ui == ""
to try to determine if one is running the vignette:
if (TRUE) {
repeat{
ui = readline("Strong evidence... ")
in_vignette <- !interactive() && ui == ""
if (ui == 2)
stop("User is...")
else if (ui == 1 || in_vignette) {
cat("Continuing analysis...")
return()
}
else
cat("Invalid input...")
}
}
#> Strong evidence...
#> Continuing analysis...
Created on 2024-09-05 with reprex v2.1.1
1