Calling RGraph to create an image file using the TERR RinR package

The RinR package provides functions that can start other versions of TERR or open-source R. Using the RinR function RGraph, you can create a graph in open-source R, and then just view the graph or save it as an image file to share with others.

Perform this task from the TERR console.

This example walks you through creating lattice graph, saved as an image (.png) file, using data available in the TERR library Sdatasets, and then displaying the results in a browser.

Remember: For information about RinR, load the package and then open the package help.
help(RinR)

Prerequisites

You must have open-source R and TERR installed on your computer. For this version of TERR, we tested with open-source R version 3.4.2.

Procedure

  1. Load the RinR package in TERR. library("RinR")
  2. Optional: If necessary, run the RinR function configureREvaluator, passing in the full path to your open-source R installation.
    This step might be required if you have installed open-source R in a non-standard location.
    configureREvaluator(REvaluator, FullPath="C:/R-3.3.2/bin/R")
    1. Run the RinR function REvaluate(version$version.string, REvaluator) to check the results.
      [1] "R version 3.3.2 (2016-10-31)"
  3. Run the RinR function RGraph, passing in arguments to that create the graphic.
    • An expression, that specifies the type of graphic you want to produce. In the example, the example is an open-source R latticed histogram.
    • The data, that is specified in a character vector or in a list. In the example, the data, singer, is from TERR Sdatasets package and is specified in a list.
    • The argument display=TRUE, which opens the graph in your default image viewer.
    h <- RGraph(print(lattice::histogram(~height|voice.part, 
    data=s)), data=list(s=Sdatasets::singer), display=TRUE)

If you want to save the resulting image as a file and share it with others, complete the following steps.

  1. Optional: If you want to save the resulting image as a file and share it with others, call the TERR base package function tempfile to create an object to contain the file extension.
    pngFile <- tempfile(fileext=".png")
  2. Optional: Call the TERR base package function writeBin, passing in the two objects created in steps 3 and 4.
    This step creates the binary file containing the image and specifying the file type.
    writeBin(h, pngFile)
  3. Call the TERR utils package function browseURL, passing in the image file.
    browseURL(pngFile)
    A default image viewer for the file type opens, displaying the image. In this example, the image shows a histogram of singer heights for each voice type in the choir.

Result


lattice graphic example