3

I have faced with the strange behavior of the .Traceback object in R.

When I try to print the short error message, it is ok and the .Traceback[[1]] has the one element. But when I try to print very long string, the .Traceback[[1]] object becomes the list of two elements. Look:

>stop(paste("short", "string"))
Error: short string
>.Traceback
[[1]]
[1] "stop(paste(\"short\", \"string\"))"

>stop(paste("very loooooooooooooooooooooooooooooooooooooooooooooooooooooong", "string"))
Error: very loooooooooooooooooooooooooooooooooooooooooooooooooooooong string
>.Traceback
[[1]]
[1] "stop(paste(\"very loooooooooooooooooooooooooooooooooooooooooooooooooooooong\", "
[2] "    \"string\"))" 

Could you help me to figure it out? I'm really confused by this unintended behavior.

Artem Klevtsov
  • 9,193
  • 6
  • 52
  • 57
  • 1
    The spillover into the new character vector element happens when the total # char in `paste` goes from 52 to 53. Also note that there is only 1 pairlist element in both cases; merely more character elements within the 1 element in the long text case. – Hack-R Jul 18 '18 at 15:56
  • @Hack-R I guess it can be changed in the `options` right – akrun Jul 18 '18 at 16:00
  • @Hack-R I am not completely sure about that – akrun Jul 18 '18 at 16:03

1 Answers1

1

Could you help me to figure it out?

It seems to be affected by options(width)

stop(paste("very loooooooooooooooooooooooooooooooooooooooooooooooooooooong", "string"))
.Traceback
#R [[1]]
#R [1] "stop(paste(\"very loooooooooooooooooooooooooooooooooooooooooooooooooooooong\", "
#R [2] "    \"string\"))" 

options(width = 9001)
stop(paste("very loooooooooooooooooooooooooooooooooooooooooooooooooooooong", "string"))
.Traceback
#R [[1]]
#R [1] "stop(paste(\"very loooooooooooooooooooooooooooooooooooooooooooooooooooooong\", " "    \"string\"))" 

This is not clear from the help page though. It is though written in help(".Traceback") that

The calls may print on more than one line, ...

Do also notice from from help(".Traceback")

Warning

It is undocumented where .Traceback is stored nor that it is visible, and this is subject to change.

so likely use traceback() instead

tr <- traceback()
all.equal(tr, .Traceback)
#R [1] TRUE