I am in the process of writing my first vignette using R Markdown and I have hit a stumbling block when putting pieces of code into a chunk. The code is a function which, when run in R, will prompt the user for a numeric value. This can't be achieved in R Markdown so it throws an error message:
Error in if (h < 1.1) { : missing value where TRUE/FALSE needed calls: ... withCallHandlers -> withVisible -> eval -> eval -> heightvalue
I know that if I run:
```{r error = TRUE}
it will allow the markdown to run and put the error message in my output (not ideal!).
I can get rid of this by putting:
```{r error = TRUE, eval = FALSE}
but this means that all of my output disappears, i.e. no prompt will be displayed in my HTML. I would like the output to remain but the error message to disappear please.
If anyone can help, that'd be fantastic.
The original piece of code, which I call with heightvalue(h), is:
heightvalue <- function(h){
h <- ask("Enter height for variable threshold (between 1.1 and 10): ")
h <- (as.numeric(h))
if(h < 1.1){
stop('VALUE OUT OF BOUNDS')
} else if(h > 10){
stop('VALUE OUT OF BOUNDS')
}
return((h))
}
Aucun commentaire:
Enregistrer un commentaire