RStudios GUI – the console

Hints for the RStudio console

Author
Published

January 10, 2024

1 Hints for working in the console

As mentioned elsewhere, the console lets you talk directly to the R interpreter and you will spend much time in the console testing out your code.

Here follows a number of practical simple hints on how to use the console:

1.1 Predictive texting

Write mean in the console and wait a short while – RStudio will present you with a list of functions etc in the current environment that starts with mean. Try scrolling through the list.

1.2 Predictive texting .. which is adaptive

Write meaning_of_life <- 52 (ENTER) to create a new variable – now try out hint #1 again and you will see this new variable has been added to the list.

1.3 Re-use and ammend previous commands

But the meaning of life is not 52, is it?1 So we need to fix that.

In the console on an empty line, simply press the keyboard up-arrow and your previous command should re-appear, amend it to 42 and press ENTER. You can use the arrows to scroll up/down through a history of you console commands, in the current session.

1.4 Sweeping away the clutter

In the top right hand corner of the console click the icon which resembles a broom. It clears the console window, but the console hisotry is retained.

1.5 Running a command from the text editor

Open an empty R script in the text editor, enter print("copy, paste, execute") (CTRL+ENTER) – this command should be copied into the console and executed immediately.

1.6 Running multiple commands from the text editor

In the text editor add another line below the first one: print("with CTRL-ENTER") – this time, highlight both lines (mouse: click+drag) before CTRL+ENTER.

Hint Check out the ‘Run’ dropdown button in the top right-hand corner of the text editor, to run all code or specific chunks.


To copy the other way, from console to text editor, use the usual mouse-hightlight, CTRL-c and CTRL-v to copy paste.

Footnotes

  1. According to the fictional supercomputer Deep Thought in Douglas Adams’ sci-fi universe, The Answer to the Ultimate Question of Life, The Universe, and Everything, is 42, but you probably already knew that :-)↩︎