[R] print(cat(bleh)) shows up strange NULL

Dan Bolser dmb at mrc-dunn.cam.ac.uk
Tue Jan 4 23:50:53 CET 2005


On Tue, 4 Jan 2005, Dan Bolser wrote:

>On 4 Jan 2005, Peter Dalgaard wrote:
>
>>Dan Bolser <dmb at mrc-dunn.cam.ac.uk> writes:
>>
>>> I am trying the following code...
>>> 
>>> for(i in 1:bins){
>>>   print(cat(c(i, length(var1[var1==i]))))
>>> }
>>> 
>>> Where var1 is a vector with zero or more values = {1, 2, ..., bins} (or
>>> something like that).
>>> 
>>> The result I get is...
>>> 
>>> 1 33NULL
>>> 2 28NULL
>>............
>>> 19 0NULL
>>> 20 3NULL
>>> 
>>> I don't know what I am doing to get those stray NULL characters printed.
>>
>>You're printing them, will you believe it...?
>> 
>>Consider this:
>>
>>> x <- cat("abc")
>>abc> print(x)
>>NULL
>>> x
>>NULL
>>> print(cat("abc"))
>>abcNULL
>>
>>I.e. cat() always returns NULL, invisibly unless you force it to be
>>printed. 
>
>never trust a cat!

I meant to add that this was causing me problems when trying to create a
file name for use with the png command.

png tries to create a 'NULL' file name, and returns a rather cryptic
message...

Error in X11(paste("png::", filename, sep = ""), width, height, pointsize,: 
	unable to start device PNG
In addition: Warning message: 
could not open PNG file `' 
> 

However, the warning provides the answer to the problem... use paste
instead of cat.

Cheers,
Dan.


>
>>
>>
>>
>
>




More information about the R-help mailing list