On Sep 19, 2009, at 11:58 AM, johannes rara wrote:

Thanks for the responses.

I think that the best way to avoid lots of hassle is that people
copy-paste their solutions from their code editor, NOT from R console.
For example, I usually save those solutions for my code archive, and
if I want to run these later on (using Tinn-R), I have to parse ">"
and "+" marks anyway.

I agree entirely but trying to change posting behavior appears to be a difficult exercise. It would also be much preferred if people would learn to post the output of dput on an object, rather than what is displayed on the console when the object is print()ed.

--
David.

-Johannes

2009/9/19 David Winsemius <dwinsem...@comcast.net>:

On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:


snip


Here's a quick version of CleanTranscript, translated to R:

CleanTranscript <- function(lines) {
lines <- grep("^[[:blank:]]*[^>+[:blank:]]*[>+]", lines, value = TRUE)
 lines <- sub("^[[:blank:]]*[^>+[:blank:]]*[>+] ?", "", lines)
}

So on systems where "clipboard" is supported, executing

source(textConnection(CleanTranscript(readLines("clipboard"))),
      echo = TRUE, max.deparse.length=Inf)

will do something similar to what the Windows "Paste commands only" menu option does, but you'd need a different incantation on other systems. And even this will sometimes mess up, e.g. it will sometimes misinterpret output
that contains > or + as input.

Duncan Murdoch

On Macs (and possibly other *NIXen) the equivalent to reading from the
"clipboard" is: pipe("pbpaste")

Testing shows that a simple modification after defining CleanTranscript
produces no error on the example above:

source(textConnection(CleanTranscript(readLines(pipe("pbpaste")))),
+        echo = TRUE, max.deparse.length=Inf)

example(mean)


snip
----
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to