Skip to content

Execution of larger blocks of pasted code often fails?

1 message · Barry Rowlingson

#
On Tue, May 28, 2013 at 7:54 AM, Mark Breman <breman.mark at gmail.com> wrote:
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.

B