Once I was wondering how to return string from function str(). I guess capture.output is one way:
capture.output package:utils R Documentation
Send Output to a Character String or File
Description:
Evaluates its arguments with the output being returned as a
character string or sent to a file. Related to 'sink' in the same
way that 'with' is related to 'attach'.
Usage:
capture.output(..., file = NULL, append = FALSE)
Arguments:
...: Expressions to be evaluated.