4.10 Use the R Interpreter in a Notebook Paragraph

An Oracle Machine Learning notebook supports multiple languages. Each paragraph is associated with a specific interpreter. To run R functions in an Oracle Machine Learning notebook, you must first connect to the R interpreter.

In an Oracle Machine Learning UI notebook, you can add multiple paragraphs, and each paragraph can be connected to different interpreters such as R or SQL or Python. You identify which interpreter to use by specifying % followed by the interpreter to use: sql, script, r, python, conda, markdown.

This example shows how to:
  • Connect to the R interpreter to run R commands in a notebook.
  • Verify the connection to Oracle Autonomous Database, and
  • Load the ORE libraries
  1. To connect to the R interpreter, type the following directive at the beginning of the notebook paragraph, and press Enter:
    %r
  2. To verify the database connection, type the following command and press Enter:
    ore.is.connected()
    Once your notebook is connected, the command returns TRUE, as shown in the screenshot here. The notebook is now connected to the R interpreter, and you are ready to run R commands in your notebook.

    Figure 4-45 Test Database Connection

    Test connection to the Oracle Database
  3. To import R Libraries, run the following commands:
    library(ORE)
    library(OREdplyr)
    Once the packages are loaded successfully, the list of ORE packages are displayed as shown in the screenshot here. Scroll down to view the entire list.

    Figure 4-46 Commands to Load R Packages

    Load R Packages