There are two main ways of interacting with R: using the built-in console or running script files. Using the R console, you can type in commands directly, but they will be forgotten once you close the session. Alternatively, you can enter R commands in a script and save it in the workspace Files.
R console can be accessed either by clicking on the R tab or by navigating to the Add dropdown menu (shown by a + sign) and selecting ‘R session’.
Before starting the session, you can select the version of R from the sidebar on the right. Once you have started the session, changing the R version in the dropdown will not affect the current session. If you want to use a different R version, you will have to open a brand-new session.
If you had previously closed an R session, you will find it listed in the same dropdown menu. Clicking on an existing session will open the R console with the same environment, meaning it will contain all the functions and variables you had previously defined.
Workspaces currently support 4.0.2, 3.6.3, 3.5.3 as well as a Legacy R 3.5.0 which can be used with scripts migrated from an Analytixagility workspace (Workspaces version 1.25 or earlier).
Using the console
Starting a new R session will open the console. You can type in your command and the output will be displayed in the R console. Any visual outputs will appear in the Plots tab on the right-hand side panel. You can click on the plot to enlarge it or save it in the workspace Blobs.
The scripts and files stored in the workspace will appear in the Files tab on the right-hand side panel. If you click on the arrow of an R file, the script will be executed in the console, whereas if you click on the name, the script will open in a text editor in a separate tab. You can modify, save and run the script (or portions of the script) from the new tab.
Creating and running R scripts
Another way to interact with R is by saving your R code in a script and then running it in the console.
Creating a new R script
You can create a new R file by navigating to the Add menu and clicking the 'New File' command. This will open a new window, where you need to enter the file name and select the type of file you want to create (R file in this case). Once the new file is created, a text editor tab will open, where you can enter your R code.
Running an R script
An R script can be run by pressing the ‘Run file’ button at the top of the text editor. You also have the option to run individual statements by highlighting them and pressing ‘Run selected’.
Executing a script opens the R console, where you can see outputs if there are any. If you haven't previously started an R session, you will be prompted to select the R version that you want your script to run in and start the session.
You can also run your script directly from the console by finding your file in the Files tab on the right-hand side panel and clicking on the arrow next to the file. Please note that you must save your script before running it in the console.
Stopping an R script
If you run an R script or command and notice that it is taking a long time to complete, you can stop it by clicking the ‘Stop’ button at the bottom of the console to terminate its execution.