This article describes how to use the Code Editor in Displayr to create and modify R-based Variables and Calculations in your Document. Note that R-based Data Sets do not use the Code Editor, for guidance see below.
Accessing R code for R Data Sets
Requirements
A Displayr document with at least one of the following:
- An existing object that is built using R code,
- An object that contains R code, or
- A new custom calculation, R variable, or R data set.
Accessing the R Code Editor
When you create a new R item, the Code Editor panel will automatically appear at the top of the page:
Otherwise, to access the Code Editor for Variables and Calculations:
- Select the object that contains R code (see above requirements).
- From the object inspector, go to the Data tab and click Show advanced options if the R Code section is not expanded.
- In the R Code section, click Edit Code, hit F2 on your keyboard, or click the Edit(F2) badge just above the object you've selected.
To re-enter a closed R code editor, you can either repeat option 2 above or else click the middle icon in the toolbar directly above the calculation when selected.
Closing the R code editor
If you click out of the calculation or deselect it, the R code editor panel will close automatically.
When you are finished editing the R code in a calculation, you can manually close the editor in one of the following ways:
- By using the X button in the upper right corner of the editor.
- By using the Hide Code button in the object inspector.
- By using clicking the middle icon in the toolbar that appears directly below the selected item.
Pinning the R code editor
You also have the option to pin the editor panel to the top of the page by clicking on the pin button in the upper right corner of the editor. Once pinned, the editor will not close, even if you select another object that's not supported by the R code editor.
If the R code editor is pinned and you select an object that's not supported or click on the page, the panel will display a message that indicates that you need to select a custom calculation to edit its R code:
Resizing and Maximizing the R code editor
You can adjust the code editor panel's height by dragging the panel up or down. The height is remembered as long as you do not clear your browsing data/cache for Displayr.
To instead maximize your view, you can click the left icon on the toolbar that appears directly above or below your selected output.
And you can exit from this view by clicking the Exit Maximized View button at the top right.
Accessing R code for R Data Sets
The code for an R Data Set:
- In the Data Sources pane, select the R data set name.
- In the object inspector, click Update.
- A dialogue with a field for the name of your data set and a code editor will pop up.
Next
Frequently Asked Questions about Using R in Displayr
How to Add a Custom Calculation
UPCOMING WEBINAR: 10 Market Research Predictions Over the Next 4 Years