Cline lets you create and run entire workflows via using prompts to a large language model. Its not widely used in the R community yet, but I expect it will be soon. You can create your entire R project, interpret the results and write a draft of your findings without writing any R code.
Cline is not available (as of writing) in RStudio. So you need to use a different IDE (Integrated Development Environment) to run your R code. Here I’ll explain how to set-up VSCode (a popular IDE) so you can use Cline.
To set up VScode for R and Cline, you’ll need:
Note that if you computer is controlled centrally by an IT department, you may need to request admin access to install software, or email IT and ask for them to come and help you.
install.packages("languageserver")
install.packages("httpgd")
(this helps improve plots in VScode)More info on vscode and R here
R --version
R
to open the R console in the terminalIf R is not found then open extensions (left hand side, boxes icon), filter by ‘enabled’ then click the R extension.
Now click the cog icon in the R extension and select ‘settings’ from the dropdown.
Search for ‘rpath’. Check that it has the correct path to R on your computer.
You can find the path by opening a terminal and typing which R
(on mac) or in a windows terminal where R
.
While you have the extension settings open search for ‘httgp’ and make sure Plot: Use Httpgd
is enabled.
Now you need to choose your large language model provider. I’m currently using Anthropic, which has a diversity of models for generating text, code and reading images. Do some web searching to find out the latest info on providers and models.
You choose depends on what you want to do and your budget. Some providers offer a free tier. You’ll need to web search for the latest info on this.
You can get the links to any supported provider from the Cline extension settings, just select the provider and then a link will appear to sign-up for that provider.
Once you’ve chosen a provider, create an account and follow their instructions for creating an API key. You will probably also need to buy some credit to use the model.
Note that if you already have a subscription account, e.g. for chatGPT, you will get need an API key to use Cline. This might be in a different section of your account settings. If you are using a subscription service you are probably paying monthly to use the provider’s web app. We need the API key to be able to use the model directly via code.
Now you’re set and ready to start using Cline to code and write text.
This is just a list of issues I’ve had and how I’ve solved them.
Plotting If your R plots look weird (like tiny font), make sure httpgp is enabled. Go back to steps above and see how to do that.
Viewing data There are various extensions for viewing csv and excel files. It is worth looking into these so that when you do View(dat)
in R you get a nice table. Some also allow editing.
Getting help to install software My computer is somewhat locked down by IT, so getting this set-up was a bit fiddly and required a few requests to IT to install software.
R markdown There are options in the R extension settings for how to knit markdown. You may need to configure these if you want to knit markdown docs from VScode. If you are having trouble knitting markdown it may mean that the path to pandoc is not set correctly. There is some helpful instructions here
R terminal crashes If I run too much R code at once (like selecting a big block then running) the terminal tends to crash. Initially I see a little highlighted box saying ‘PTY HOST’. Then I need to close all the terminals (with the bin icon) and start again. Try radian if this is a problem. You can also code run line-by-line or source whole scripts from the terminal (which works fine). I tried debugging this by increasing the buffer but to on avail.
Shortcut keys (on osx) cmd-/ to comment uncomment lines. cmd-shift-p to open the command palette, cmd-b to open the file explorer, cmd-enter to run lines or selection of R code, cmd-shift-c to open terminal in new window, cntrl-shift-` to open a new terminal in vs code.
Radian is a terminal editor that is a bit nicer than the base R one. It does autocomplete in the terminal (like Rstudio does in the console), colours code/brackets etc… and allows multi-line editing in the terminal.
To set this up, install radian (you need python to do this). More instructions here.
Then go to the terminal and find the path where radian is installed (e.g. which radian
on mac or where radian
on windows).
Now open your settings in VScode (cmd-,) and search for ‘rterm’ (stands for ‘R Terminal’, don’t change the rpath which we set just before). Add the path to radian to the rterm setting. Also search for the setting ‘R: Bracketed Paste’ and make sure it is enabled.
Designed by Chris Brown. Source on Github