You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be slight issue of inconsistency in how knitr wraps lines in warning messages (and error messages) compared to usual R output:
warning_fun<-function(){
long_function_name<-function(){
warning("this is a relatively long warning message which should be on new line.")
}
long_function_name()
}
On knitted PDF:
warning_fun()
## Warning in long_function_name(): this is a relatively long warning message## which should be on new line.
On R console:
warning_fun()
# Warning message:# In long_function_name() :# this is a relatively long warning message which should be on new line.
It seems that if I set options(warn = 1) then I get similar warning in R console (but warning itself is still on a new line):
options(warn=1)
warning_fun()
# Warning in long_function_name() :# this is a relatively long warning message which should be on new line.
This seems minor issue itself, but I suspect this relates to the issue that some warnings and errors to become truncated in PDFs due to long function call:
sqrt("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
## Error in sqrt("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"): non-numeric argu
On R console:
sqrt("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
# Error in sqrt("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") : # non-numeric argument to mathematical function
The text was updated successfully, but these errors were encountered:
The inconsistency looks minor, and I tend not to change it at this point. If the main issue here is to solve the truncation of text in PDF, you can customize the error/warning hook function to wrap the error/warning message, e.g.
library(knitr)
local({
hook_error=knit_hooks$get('error')
knit_hooks$set(error=function(x, options) {
# process the error message here; you may print(x)/gsub()/strwrap(x)/...
hook_error(x, options)
})
})
There is endless pain like this with PDFs due to the constraint of page sizes. I don't think it completely solves the problem even if I move the message to a new line. For example, your function name may be so wide that it may have already exceeded the page margin. I may be able to treat the symptom you had there, but it definitely does not treat the disease.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.
There seems to be slight issue of inconsistency in how
knitr
wraps lines in warning messages (and error messages) compared to usual R output:On knitted PDF:
On R console:
It seems that if I set
options(warn = 1)
then I get similar warning in R console (but warning itself is still on a new line):This seems minor issue itself, but I suspect this relates to the issue that some warnings and errors to become truncated in PDFs due to long function call:
On R console:
The text was updated successfully, but these errors were encountered: