An essential difference between cat and print is the class of the object they return. This difference has practical consequences for what you can do with the returned object.
print returns a character vector:
> print(paste("a", 100* 1:3))
"a 100" "a 200" "a 300"
> class(print(paste("a", 100* 1:3)))
"a 100" "a 200" "a 300"
"character"
cat returns an object of class NULL:
> cat(paste("a", 100* 1:3))
a 100 a 200 a 300
> class(cat(paste("a", 100* 1:3)))
a 100 a 200 a 300
"NULL"
网友评论