R script window
Menu location: Continue in R on the right-click menu of a result in a report, the R button on the toolbar of a report, or File > New R session for an empty R script.
The R script window holds an R script and runs it with the R installed on your computer. Continue in R on a result writes the script of that result: the data as the analysis used them, read from the workbook, the settings, and the analysis as the R section of its help topic shows it. The R button on the toolbar of a report does the same for the result the cursor is in, or for the latest result when the cursor is in none. The script is short and plain, so that you can read it, change it and run it again, or take it to R or RStudio. Every analysis whose help topic has an R section has such a script; for the others, Open data and settings in R gives the data and settings for you to add the analysis.
A script opened with Continue in R runs as soon as it opens. File > New R session opens a blank R editor without running anything; type or paste your code and choose Run. What R prints appears below the editor, with charts and links to files written by the run. Run on the toolbar runs the current script again after you edit it; a run still going is stopped first. Clear output, under the arrow at the end of the toolbar, clears what R printed, and Output folder opens the R folder of your StatsDirect documents. Commands appear after their prompts, with their output beneath. Open in R saves the script as an R file and opens it in RStudio when that is installed, otherwise in R's own window. AI assistance opens the Script AI pane for questions about the script, its output and the methods.
To put a chart in a report, right-click its picture in the R output and choose Copy image. In the report, use Add text if you need a new section, place the cursor there, and choose Paste or press Ctrl+V. An SVG chart copied from R output remains vector SVG in a StatsDirect report, and pastes into PowerPoint or Word as a vector graphic, which Office can convert to shapes, as a chart copied from a report does; Paste Special there offers a PNG for an application that needs a picture. PNG charts paste as embedded pictures. The report keeps its own copy, so the R output file is not needed to reopen it. In StatsDirect 5.2.3, press Enter with the picture selected, or with the cursor immediately after it, to continue writing below it in the same result. Undo and Redo include the paste and the new paragraph.
Save and Save As on the File menu keep the script as an R file, which R and RStudio open, and Open brings a saved script back. Cut, Copy, Paste and Find work on the script as in any editor. Right-click in the code editor for Undo, Redo, Cut, Copy, Paste, Delete and Select All.
The first lines of a script say which workbook and sheet its data came from and when they were read, and note any column that has changed in the workbook since the analysis ran, or could not be read, so that you can put its values in by hand. If no R is installed, StatsDirect offers to install it when a script is first run.
Help on this window opens this topic while the window is empty; once a script of a result is in it, Help opens that result's topic, whose R section the script follows.