Christophe Weblog Wiki Code Publications Music
alternative printing for the REPL
authorChristophe Rhodes <csr21@cantab.net>
Fri, 3 Sep 2010 07:10:09 +0000 (08:10 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Fri, 3 Sep 2010 07:10:09 +0000 (08:10 +0100)
instead of using print(), use str().  Also, be even more cautious
about cleaning up in printToString; previously, errors in printing
would lead to a sink to a closed fifo...

Printing is still not really right, and I forsee that we will end up
writing our own printer to get something more lispy.  But at least
this approach tends not to dump huge tables into the REPL.

swank.R

diff --git a/swank.R b/swank.R
index 99f508bc153379b56c4586b6f61e7ee0db6b6c93..0a309ef7da9b22576d945c26984874f6aa58ef88 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -247,7 +247,11 @@ writeSexpToString <- function(obj) {
 
 printToString <- function(val) {
   f <- fifo("")
-  tryCatch({ sink(f); print(val); sink(); readLines(f) },
+  sink(f)
+  tryCatch({
+    tryCatch(str(val, indent.str="", list.len=5, max.level=2),
+             finally=sink())
+    readLines(f) },
            finally=close(f))
 }