Capture current cursor's line contents


#1

Hi all,

So two of my most hated tasks when I'm coding in R is evaluating if an if statement will evaluate positive or not, and switching the order of inputs from position 2,3 to 3,2. I was thinking about creating an Rstudio addin to accomplish these, but I'm having trouble right out of the gate... I can't seem to find any way to capture the "current line" in the current open script.

I've been messing around w/ rstudioapi::getActiveDocumentContext() and findLineNum(), had a look at old posts but it seems there's nothing perfect? I mean there must be a way to do it... since Rstudio has a "run current line" feature... but perhaps this isn't accessible externally?

To be clear, what I'd want is to start from this:

if (SecError & Sys.time() > paste(Sys.Date(), "10:00:00 UTC")){

Have a shortcut that I run to only evaluate:

SecError & Sys.time() > paste(Sys.Date(), "10:00:00 UTC")

Which would be easy, I'll create the wrapper for it, if I could just capture that text. Is there any way to do capture that line of code if my cursor is resting on it?

Thanks for looking!