Designate lines of code to run in development mode

rstudio

#1

Suggestion for a new feature in RStudio: "Toggle" lines of code to run in development mode.

Use Case: I am developing code and have many diagnostic type commands within the code - that check out data, say using head(), glimpse(), or that produces interim graphs - so that I can check out that my code is running correctly. Perhaps some of these commands take a while to run.

But, if I am generally happy with the code and want to run whole blocks of code, say from line 1 to my current line (say using ctrl+alt+B), my diagnostic commands throughout the code will run again, slowing down the process. I could go back and comment out all my diagnostics, but then if I want them back I have to uncomment them.

Would there be a way to click/toggle a button in RStudio that would skip over designated (diagnostic) code? Perhaps the diagnostic code lines could be prefixed with "*" so that RStudio can know which lines to skip when the button is depressed.

Thank you.


#2

IMHO something like this would be better expressed directly in code, with e.g.

# toggle flag as needed
verbose <- FALSE

if (verbose)
  glimpse(object)

If you wanted, you could create an RStudio Addin to e.g. toggle the 'verbose' flag as needed before executing your code.


#3

Hi Kevin thanks for the response! But in that case for every diagnostic command I type would have to prefix it with "if (verbose) ..." I was hoping there could be a simple button toggle and maybe a simple special (1) character prefix in front of diagnostic code, such as * head(). Currently, I have a global variable that I set, and a common diagnostic function runs, or doesn't run, depending on whether I set the global variable to 'y' or 'n' (like as you suggested) but this only works for functions that I have written that check for the global variable toggle, not for simple glimpse()'s for example.


#4

You could use a special comment marker at the end of the line; e.g.

glimpse(object)  #*
use(object)

and then write an addin that finds lines ending with this marker, and toggles them 'on' or 'off' (commenting or uncommenting them appropriately).


#5

Thanks! I would need to figure out how to write an add-in... but I'm always willing to learn...