clean up error and event handling in R Markdown template discovery