[R] Execution of larger blocks of pasted code often fails?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue May 28 10:00:56 CEST 2013

On Tue, May 28, 2013 at 7:54 AM, Mark Breman <breman.mark at gmail.com> wrote:
> Hello List,
> When i paste a large block of R code from an editor to the R command line
> the execution of the code will often fail at some point because it is not
> pasted as it was copied.

 This reminds me of the Tommy Cooper joke (I can't do the voice,
especially over email):

Man: "Doctor, it hurts when I do this" [waves arm about]
Doc: "Well don't do that then".

 Cutting and pasting code - especially large blocks of code - is a
poor way to work with R. Make your code re-usable by putting it in
functions with sensible arguments and meaningful return values. Debug
your functions with little test data sets, or go the whole hog and use
package:testthat for writing test suites. Organise your functions into
packages and use package:devtools to make packages REALLY REALLY easy.
 Easier than having a big text file with all the R code you've ever
written in, and then pasting chunks of into R every time. Or pasting
it back into your big text file and then changing a little bit of it
so you now have two very similar chunks of R code with the same bug
now in two positions....

 Take a day to read up on how to effectively work with R with
functions and packages, then revisit your work and see how that can
apply to you. You'll get that day back within a couple of weeks.


More information about the R-help mailing list