There are different formats that a Calculation (R Output) can be displayed as, though not all options may be available for a given output. The software assesses what types of outputs are available given the final calculation being returned, and will pick the "best" option (i.e. if you create a matrix in R it will be shown as a table). Other available options are shown in the dropdown in the object inspector under Properties > OUTPUT > Show as:
- Text
- Plot
- Table
- Widgets (e.g. D3)
- Help pages
Example
The following R CODE can be displayed as either Text (like you would see in an R terminal but that you can customize via Properties > APPEARANCE) or a Table:
c(1,2,3,4)
Show as > Text gives you an output like:
Show as > Table gives you an output like:
Surprising aspects of R
Occasionally, R code has surprising aspects. For example, mostly charting code will return NULL, but not always. In particular, barplot(), when applied to vectors, returns a matrix.
x = barplot(1:7, c(45, 2, 8, 9, 23, 17, 38))
So whilst a chart is typically what is expected to be seen, the value of 'x' in this example is a matrix. It is invisible, but nonetheless, that is the return value. This means that if 'x' is referenced elsewhere in the software, it will have the value of the matrix. Indeed, in this case, the software will recognize that a matrix is returned, but a chart has also been produced, so will present the user with the choice: