See what Ctrl-A does. This should take you to the beginning of the paragraph, but you'll have to test to see what RStudio considers a paragraph in that situation – and whether it supports the macOS EMACS keyboard shortcuts.
I'd see if the Set Find Pasteboard action works with RStudio. If it does you might be able to get fancy using some regex.
The difficulty is telling KM when to stop.
I saw that in your cases, both the beginning of the selection have a blank line before it and both the lines do not have any indentations (space or tab).
I made this macro based on these two characteristics. Hope it works for you in most cases.
First, please post a screenshot of only the region of interest on your screen -- not the entire screen.
When you post the entire screen the details are hard to read.
So let's look at the region of interest:
Unfortunately, I don't know of any way to select text based on the actual text involved, in this case "chickwts", UNLESS the app supports AppleScript that can access the text and characters in the window.
From a quick search, it appears that RStudio no longer supports AppleScript . You can double-check by viewing the Scripting Dictionary in Script Editor (menu file > open dictionary), and look for RStudio.
There are macOS shortcuts to select to end/start of line, and end/start of paragraph, where a paragraph is delimited by CR or LF.
The only idea I have involves some manual interaction.
You could have KM ask how many lines up to select, and then do something like this:
Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.