get R console to highlight errors in red

2019-02-25 17:32发布

A lot of the time I paste code for evaluation into the R console. Sometimes errors occur in the middle of the statements I pasted and I miss them because they blend in with the rest of the stuff on the screen. Is there a way to make them stand out via color coding?

4条回答
劳资没心,怎么记你
2楼-- · 2019-02-25 18:18

I would suggest using RStudio. It has many color options for the console and file text that are really simple to change.

Here's how mine looks. It makes error, warnings, and messages really easy to spot.

enter image description here

查看更多
The star\"
3楼-- · 2019-02-25 18:19

On linux or mac, you can simply load the colorout package and your errors will show up in red.

enter image description here

查看更多
SAY GOODBYE
4楼-- · 2019-02-25 18:19

Try these:

stop("an error occurred")

message("an error occurred")

cat("error occurred", file=stderr())

查看更多
太酷不给撩
5楼-- · 2019-02-25 18:27

from ?base::options error: either a function or an expression governing the handling of non-catastrophic errors such as those generated by stop as well as by signals and internally detected errors. If the option is a function, a call to that function, with no arguments, is generated as the expression. The default value is NULL: see stop for the behaviour in that case. The functions dump.frames and recover provide alternatives that allow post-mortem debugging. Note that these need to specified as e.g. options(error=utils::recover) in startup files such as ‘.Rprofile’.

So, I guess you could modify your .Rprofile to handle errors differently, if stopping is too much maybe you can surround them with some line-breaks to make them stand out in your code.

查看更多
登录 后发表回答