Size of string in message function in R
Asked Answered
R

1

13

There seems to be a limit on the size of the string used in message. The following only prints until number 1859 (Using R v3.1.3 on 64 bit Win7 machine)

message(paste(seq(1,2000),collapse = "-"))

while

cat(paste(seq(1,2000),collapse = "-"))

prints it all. Is this a bug?

Rocray answered 21/5, 2015 at 10:30 Comment(7)
Using R 3.2.0 on a linux machine prints it allEdouard
reproducible on 3.1.2, 64-bit MacOSMccarver
I use message to print the log from C++ code run in a R package. Given a verbose option this can be quite large.Rocray
You can have your c++ code to the logging (but that would go to a different stream). But you should probably think about a 'message chopper' that parcels it out into several shorter chunks. Assuming 'unlimited' string length for logging is ... maybe too much. Remember 80 char limits? ;-)Excavate
I mainly use the verbose option for debugging so implementing a 'message chopper' may be overkill. Anyway the current hack is just to use cat instead even though some say that message is more consistent.Rocray
@DirkEddelbuettel RJDBC query error message is a nice example of the utility of big messages. For big queries created by scripts, you can't see where is the error. I applied tryCatch to cat the error instead of message it, but IMHO it's very inelegant.Pepsinogen
I am not sure if it is relevant but message() uses stderr, while cat() uses stdout. I can reproduce this with R 3.4.0 on Win10Digest
T
1

There's a good solution in this question:

avoid string printed to console getting truncated (in RStudio)

As it suggests, if you're using RStudio, just go to Global Options -> Code -> Display -> Limit length of lines displayed in the console to:

And change the value to zero. It works for me.

Trilateral answered 9/7, 2017 at 4:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.