There are two distinct ways that Displayr calculates R code:
- The main way is to send the required data and calculations to a server on the cloud that hosts the R Foundation's R software, for specifics see How R Works Differently in Displayr Compared to Other Programs.
- Where the code is suitably straightforward, it is calculated using Displayr's Native R Interpreter, which is typically much faster as calculations are done within the app itself. This helps to Minimize the Size and Distance of Data Being Moved.
This article describes:
- Key differences between the R Foundation's R software and Displayr's Native R Interpreter
- How Displayr determines when to perform calculations using Displayr's Native R Interpreter
- How to check if code has been run on the R Server or via Displayr's Native R Interpreter
- How to force code to run on the R Server
- Functionality supported by Displayr's Native R Interpreter
- Use AsArray when subscripting tables
- How to request additional functions
Key differences between the R Foundation's R software and Displayr's Native R Interpreter
R code is written using the R language, and R language can only be definitively processed by the R Foundation's R software, which is an entirely separate software from Displayr. For various technical and legal reasons, this R software is installed on cloud servers, typically referred to in our documentation as an R Server. For Displayr to process the R code, the required data and R code are sent to the R servers and the output is returned to Displayr to be shown in the Displayr software.
Bigger calculations will typically be faster when run in Displayr than when run on your PC, as we use very large and fast servers to perform R calculations. However, small, simple calculations are relatively slower to process using the R servers, mainly due to overhead. This overhead cost is unavoidable and creates a minimum threshold for how fast R code can be processed. For example, 1 + 1 may take .3 of a second or even more if many other things are calculated simultaneously.
This is where Displayr's Native R Interpreter comes in. The Native R Interpreter identifies specific types of simple R code, and instead of sending that request to the R servers, processes the code inside the Displayr software directly. Because of this, it calculates 1 + 1 in essentially 0 seconds.
Important to note: Due to differences in how the R Foundation addresses numeric precision versus Microsoft (whose technology we use to create Displayr's Native R Interpreter), the Native R Interpreter does not always get exactly the same answer as calculated by the R Server. However, we are unaware of any situation where the differences do or could have any meaningful impact. If this becomes an issue, one can always force code to run on the R Server (see below).
How Displayr determines when to perform calculations using Displayr's Native R Interpreter
Displayr reviews the R code and determines whether to use the Native R Interpreter or an R Server. Suppose your code only uses Functionality supported by Displayr's Native R Interpreter, the code will always be run using Displayr's Native R Interpreter unless you override the Calculation to run on the R Server.
How to check if code has been run on the R Server or via Displayr's Native R Interpreter
To see whether the code has been run using Displayr's Native R Interpreter or the R Server, you can examine the Calculation timings in the raw R output. Simply:
- Select the Calculation.
- Check the General > Output > Show raw R output checkbox.
If the code has been run using Displayr's Native R Interpreter, it will show at the top: This code has been optimized for fast execution. To see the full raw R output, check 'Show all output' in the object inspector.
How to force code to run on the R Server
It is sometimes preferable to use the R Server rather than Displayr's Native R Interpreter. In particular, this is desirable when:
- There is a lot of data. (The Native R Interpreter is fast for small data, not for bigger data.)
- You want to look at diagnostics generated via print statements.
- You'd like to compare.
You can avoid using Displayr's Native R Interpreter by either:
- Checking Properties > OUTPUT > Show all output.
- Or inserting a line of code containing a 0-second pause
Sys.sleep(0)
into your calculations. Sys.sleep is an unsupported function by the Native R Interpreter, and thus, the code must be processed by the R Server.
You can confirm the code has been processed by the R Server when the raw R output does not show the Interpreter's message (above) and you see the lines of R code and R server timings:
Functionality supported by Displayr's Native R Interpreter
Category | What's supported |
Assignment operators |
=, <-, <<- |
Arithmetic operators | +, -, *, /, ^, %%, %/%, () |
Logical operators | !, ==, !=, >, <, >=, <=, &, &&, |, || |
Set operators | %in% |
Subscripts |
Using the You can also use the name in backticks `` |
List operators | Note that only backticks are supported, so while you can't use [["object
name"]] , you can use x$`object name`
|
S3 class support | factor, ordered, table, array, matrix, data.frame |
Flow | if, else, ifelse |
Other functions |
c() trimws() paste() paste0() rowSums() function() AsArray() |
Use AsArray when subscripting tables
One of the most common things to do when writing code in Displayr is to subscript a table. For example, if you want to select the fourth column of table.Q5, you write table.Q5[, 4]
. When the table you are subscripting is created by Displayr (e.g., a crosstab), this very simple code will always go via the R Servers and won't use the Native R Interpreter. This is because most of Displayr's tables contain a lot of hidden information (e.g., significance testing results).
If you wrap the table name in the AsArray function, the subscriping can then be performed using the Native R Intepreter (e.g., AsArray(table.Q5)[, 4]
). The resulting table will lose much of its metadata (e.g., it no longer contains significance testing information).
How to request additional functions
To request additional functions, either upvote existing requests or create new requests in the category called Native R Interpreter at https://displayr.canny.io/displayr.