R: as_graph command, and other related tools for #521

Unfinished, especially the documentation and the automatic
input format detection.