The problem with your use of cat
above is that cat(x)
writes x
to output, not to a variable. If you wanted to write to a string, you could do:
capture.output(cat(blah))
which as the name implies, captures the output in a string to return the desired result. However, this is not the preferred method, just an explanation by way of an alternate solution.