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

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Jan 4 23:40:20 CET 2005


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. 


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list