sebastian-c / overflow

An R package to assist people answering R questions on Stack Overflow
14 stars 12 forks source link

Extending flexibility of SOcheck #12

Open mrdwab opened 11 years ago

mrdwab commented 11 years ago

I think SOcheck is a great idea, but I wonder if re-entering code in curly braces is going to be the typical usage scenario.

Perhaps it can be extended in the following way: Allow as input either:

  1. Contents within curly braces, as you've done
  2. Access to "clipboard"
  3. Copying the contents of "~/.active-rstudio-document" as the sourcefile (working under the assumption that RStudio is a popular IDE for R)

This could probably be done easily with a switch statement, and I think it would make the function a little bit more practical to use. For example, a lot of times, I would have a separate script tab open in RStudio where I write the code for my SO answers. It would be more useful for me if I could simply type SOcheck() in the console, and have the active document checked with vanilla R.

sebastian-c commented 11 years ago

That sounds like a great idea. I checked what happens if you put source("~/.active-rstudio-document", echo=TRUE) in your script absent-mindedly and it gives Error in mode(expr) : node stack overflow, which I thought was appropriate.

sebastian-c commented 11 years ago

I'm just trying to think how to differentiate those three options. It's difficult to use switch for the curly braces situation as that will cause it to be evaluated prematurely. Perhaps something like function(x, type) where type is one of "code", "rstudio" or "clipboard" (or even R file?).

sebastian-c commented 11 years ago

Ah, I just found out that the latest version of devtools includes a set of eval_clean functions which essentially do the same thing as this function does.