[R] Simple cat statement - output truncated

Don MacQueen macq at llnl.gov
Fri Jul 17 00:00:57 CEST 2009


I suppose it's conceivable that your object named "object" has some 
non-standard character(s) in it that cause the code underlying cat() 
to do something weird. For example,

>  cat('abcdef','\r','\n')
  bcdef

Appears to truncate the first character.

Basic debugging suggests breaking down the problem expression into 
its components in the hopes that the problem will manifest itself. 
So, what happens if  you do just

   paste(object$components[1], object$components[2], 
object$components[3], object$components[4], sep = ",")

Or simpler yet, what happens if you do each of these?

   cat(object$components[1],'\n')
   cat(object$components[2] ,'\n')
   cat(object$components[3] ,'\n')
   cat(object$components[4] ,'\n')

And are any of these very different if you use print() instead of 
cat(), without the ,'\n', of course.

-Don

At 9:11 AM -0700 7/16/09, <rkevinburton at charter.net> wrote:
>It has to be related to 'cat' because the output of 'cat' is 
>truncated. I am just tyring to find out some possible reasons as to 
>why it is truncated. I have been unable to form an array like is in 
>the test program. Do you think there is something else that is 
>gobbling up the output from cat that would make it appear to be 
>truncated?
>
>Kevin
>
>---- Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>>  On 7/16/2009 10:21 AM, rkevinburton at charter.net wrote:
>>  > So then I am to assume that the output of 'cat' can be truncated 
>>by passing it "bad" arrays.
>>
>>  I certainly wouldn't draw that conclusion.  Without a reproducible
>>  example, my assumption would be that it is unrelated to cat().
>>
>>  Duncan Murdoch
>>
>>  > That is the only difference between the "reproducible" code you 
>>show and mine. It is just a theory but say that the components 
>>array is not dimmensioned for 4 elements. It seems a little strange 
>>if that is the case that a reference error is not thrown and just 
>>the output of the cat call is affected.
>>  >
>>  > Kevin
>>  >
>>  > ---- Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>>  >> On 7/15/2009 9:53 AM, rkevinburton at charter.net wrote:
>>  >> > I have a statement:
>>  >> >
>>  >> >     cat("myforecast ETS(", paste(object$components[1], 
>>object$components[2], object$components[3], object$components[4], 
>>sep = ","), ") ", n, "\n")
>>  >> >
>>  >> > That generates:
>>  >> >
>>  >> > cast ETS( A,N,N,FALSE )  3
>>  >> >
>>  >> > Anyone guess as to why the first 5 letters are truncated/missing?
>>  >>
>>  >> You are probably being punished for posting non-reproducible code*.
>>  >>
>>  >> When I try a reproducible version of the line above, things look fine:
>>  >>
>>  >>  > cat("myforecast ETS(", paste("A","N","N",FALSE, sep = ","), ") ", 3,
>>  >> "\n")
>>  >> myforecast ETS( A,N,N,FALSE )  3
>>  >>
>>  >>
>>  >> Duncan Murdoch
>>  >>
>  > >> * R has a new predictive punishment module.  It punishes you for things
>  > >> it knows you will do later.
>  >
>
>______________________________________________
>R-help at r-project.org mailing list
>https://*stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062




More information about the R-help mailing list