paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents....

25
Hello, and welcome to this online, self-paced lesson entitled “Getting Started with ORE.” This session is part of an eight-lesson tutorial series on Oracle R Enterprise. My name is Brian Pottle. I will be your guide for the next 45 minutes of interactive lectures and review sessions on this lesson. Getting Started with ORE - 1

Transcript of paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents....

Page 1: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Hello, and welcome to this online, self-paced lesson entitled “Getting Started with ORE.”

This session is part of an eight-lesson tutorial series on Oracle R Enterprise.

My name is Brian Pottle. I will be your guide for the next 45 minutes of interactive lectures

and review sessions on this lesson.

Getting Started with ORE - 1

Page 2: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Introduction

Before we begin, take a look at some of the features of this Flash-based course player. If you’ve viewed a similar self-paced course in the past, feel free to skip this slide.

Outline

This is the Outline tab. It’s set up to automatically progress through the course in a linear fashion, but you can also review the material in any order. Just click a slide title in the outline to display its contents.

Transcript

Click the Transcript tab to view the audio transcript for each slide.

Search

Click the Search tab to find specific information in the course.

Player Controls

Use these controls to pause, play, or move to the previous or next slide. Use the interactive progress bar to fast forward or rewind the current slide. Some interactive slides in this course may contain additional navigation and controls.

Attachments

Click the Attachments button to access any attachments associated with this course.

Getting Started with ORE - 2

Page 3: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Getting Started with ORE - 3

Page 4: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

“Getting Started with ORE” is the second of eight self-study lessons on Oracle R

Enterprise.

Getting Started with ORE - 4

Page 5: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

In this lesson, you’ll learn about the prerequisites for using ORE, and you will be directed

to the associated documentation.

Then, you’ll learn how to start up R and ORE.

Finally, you’ll learn about some basic ORE operations, including the initial ORE

connection to any Oracle database.

So first, prerequisites for using ORE.

Getting Started with ORE - 5

Page 6: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Here are the software prerequisites for ORE:

The preferred version of Oracle Database is 12c, release 1. The minimum version of

Oracle Database is 11g, release 2, version 11.2.0.3.

In addition, ORE requires that you install R both on the user’s desktop, and all database

nodes that you will use.

For more information on installation instructions, see the ORE 1.4 Installation Guide.

6 Getting Started with ORE - 6

Page 7: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

This slide includes a series of screen captures to familiarize you with the CRAN website.

Before installing R, please check your ORE release notes to verify which versions of R

are supported.

First, on the home page (cran.r-project.org), select the platform for your R installation. In

this example, we select Windows.

Note: Oracle does not support the Macintosh operating system.

Next, select Install R for the first time.

Then, click the link for previous releases.

Finally, select release 3.0.1 or later. Again, verify the latest supported version of R in your

ORE installation documentation before installing R.

At this point, click the link for the selected R version. Here, you are prompted to confirm

that you want to install the software. Simply click through to the installer. As with most

Windows software, accept the default settings or customize the installation. For use with

ORE, simply accept the defaults.

7 Getting Started with ORE - 7

Page 8: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Although specific installation steps are not covered here, the basic four-step installation

process is this:

1. First, install the proper version of Oracle database, as mentioned previously.

2. Then, install R on both the user machine and database node platforms. Recall that R

3.0.1 is the ORE 1.4 certified version. You can install R from the CRAN website, or

you can use the Oracle R distribution on Linux. For download URLs, see the ORE

page on the Oracle Technology Network.

3. Next, install ORE. The official installation documentation is on the ORE page on the

Oracle Technology Network.

4. After you install ORE, you may set up the .Rprofile script. This optional script may be

used to automatically load ORE packages and connect to a prespecified Oracle

Database from the client. We’ll look at the .Rprofile script shortly.

8 Getting Started with ORE - 8

Page 9: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Now, let’s take a brief look at the .Rprofile file. This file applies to both Windows and

Linux installations, and its purpose is three-fold:

• First, it loads the ORE library, which starts up Oracle R Enterprise.

• Then, it defines database connection credentials.

• Finally, it connects to the specified database by using the ore.connect() function.

We’ll examine more about database connections later.

When this file executes, you are connected to the specified database, and you are ready

to work with ORE and your Oracle database.

Getting Started with ORE - 9

Page 10: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Next, you’ll learn how to start an R session and an Oracle R Enterprise session.

Getting Started with ORE - 10

Page 11: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

To run R on Windows, simply double-click the desktop icon or run it from your installed R

GUI executable file.

At the R command prompt, you execute functions to accomplish tasks.

For example, the slide shows two simple functions, a form of which was shown in the

previous lesson. R includes a command stack, which lets you move backward or forward

through executed statements by using the up and down arrows.

You can quit R by invoking the quit() function or by using the main menu.

• When you quit an R session, you are prompted to save the workspace image.

• The workspace image is your current R working environment. It includes your user-

defined objects, such as vectors, matrixes, data frames, lists, and functions.

• When you end an R session, you can save an image of this session so that the

workspace is automatically reloaded when you start R.

• It is recommended that you don’t save your workspace image until you become

more familiar with R and ORE.

11 Getting Started with ORE - 11

Page 12: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

In Windows, you can start R and ORE together by using the .Rprofile file.

With ORE installed and Rprofile in place, the required environment variables are

automatically established.

As shown in the slide, R sends messages to the console to indicate when:

• The database connection is initiated, and then

• When the database connection is completed.

After you are connected to the database, the R prompt appears. At this point, enter any R

or ORE function at the console.

In the example, the executed ore.ls() function produces a list of available tables. We’ll

examine a number of basic ORE functions a little bit later, including those that enable you

to connect to R and ORE directly, without using the .Rprofile file.

12 Getting Started with ORE - 12

Page 13: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

You run R and ORE on Linux by doing virtually the same thing as on Windows.

To use .Rprofile on the Linux platform, you must copy the .Rprofile file to the home directory and ensure that the R_PROFILE_USER environment variable identifies the

.Rprofile file.

Then, simply start R in the same fashion as on Windows. As shown in the slide, R sends

similar messages to the console. The messages indicate when the database connection

is initiated, and then when the database connection is completed. At this point, the R

prompt appears, and you can enter any R or ORE command at the command line.

Because ORE is associated with a database instance, you can connect to any supported

Oracle database, including on Oracle Exadata, in the same way.

13 Getting Started with ORE - 13

Page 14: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

In this last section, you’ll learn about the initial Oracle Database connection and some

basic ORE operations.

Getting Started with ORE - 14

Page 15: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Let’s take a look at a few basic operations that are associated with database interaction.

These are some of the initial ORE connection functions and basic operations for looking

at Oracle Database tables in R.

First, you can connect to Oracle Database explicitly by using the ore.connect() function.

You can use this function for two purposes:

• If you do not want to use the .Rprofile option

• When you want to connect to a new database during an R session, because only

one database connection is active at a time.

With ore.connect(), you specify the required connection parameters, including User, SID,

Host, Password, and Port. This first example connects to the database with the specified

schema for all tables and views in that schema.

To let R know which tables are available, use the ore.sync() function.

• This function lets you synchronize the R environment with proxy R objects of tables

and views that are currently in the database.

• For example, if you created or removed tables or views in the database since your

last R session, the function updates the environment so that you see the most

current tables and views for the specified schema during your R session.

• As we’ll see later, this function contains several other options.

Use the ore.attach() function to add objects for the specified schema to the R

environment search path.

• In the example, the database objects that are associated with the rquser schema

are added to the R environment search path.

• As you will see later, R provides a series of environments that are searched so that

Getting Started with ORE - 15

Page 16: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Here is a simple example of connecting to an Oracle Database that has ORE installed.

First, we can check to see if we are already connected by using is.ore.connected().

In this example, we're connecting to the rquser schema with a SID of orcl on the local

host. We specify the password here, but there are other options to avoid clear text

passwords.

The parameter all=TRUE loads metadata about all schema tables into ore.frame

objects, making them available for use as R objects with the same name as the table.

More on this later.

Finally, the ore.ls() function lists all available tables by name.

Getting Started with ORE - 16

Page 17: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

There are several other options for connecting to Oracle Database with the ore.connect() function. Some of these are shown here:

The first example uses the service name instead of the SID. As shown before, all object

metadata is loaded for the specified schema. In addition, the default port of 1521 is used.

The next example uses Oracle Wallet. Passwords for connecting to databases can be

stored in this client-side, secure software container, which may be used to store

authentication and signing credentials. By using Oracle Wallet, application code, batch

jobs, and scripts no longer need to embed usernames and passwords.

The third example uses the easy connect string, along with providing the username and

password.

Finally, you can connect to the local database by providing a NULL connect string.

Getting Started with ORE - 17

Page 18: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

After connecting to a database, you can interact with schema objects in various ways.

With the ore.create() function, you can create a database table or view from an existing

table.

• When creating a table, use the table parameter to specify the new table name.

• When creating a view, use the view parameter to specify the new view name.

You can also use the ore.drop() function to drop tables or views.

In addition, ORE can store R objects as temporary database objects.

• With the ore.push() function, you create a temporary database object that returns a

handle to the object. Use this handle to access the temporary object from other R

scripts.

• With ore.push(), you can put data from a data.frame, matrix, or vector into a table,

or from a list or model into a serialized object.

• These temporary objects are available only for the current session. When the R

session ends, the temporary objects are automatically cleaned up.

As mentioned previously, the ore.sync() function synchronizes ORE proxy objects in R

with tables and views in the database, on a per schema basis.

In the examples shown here:

• The first synchronizes objects for the currently connected database user.

• The second synchronizes objects for a named schema: rquser.

• The third use synchronizes two named tables—ONTIME_S and NARROW—in the

currently connected schema.

• The fourth use synchronizes two named tables in a specified schema.

18 Getting Started with ORE - 18

Page 19: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

At the top of this slide, we show several uses of the ore.ls() function.

• When ore.ls() has no argument, as shown in the first use, a list of all available

database objects in the R environment is returned. However, you can restrict this

list by adding arguments to the function.

• In the second use of the function, you see only those objects that are associated with the rquser schema.

• In the third use, you see only a list of those objects in the rquser schema that

start with a period, such as internal functions or objects. If you use FALSE instead

of TRUE in this usage, all objects whose names do not start with a period are

returned.

• In the fourth use, only objects that start with the text string specified in the pattern

option are returned.

If you no longer want to see the objects in a given schema, use the ore.detach() function.

This function removes a named schema’s environment from the R object search

As you’ve seen before, the ore.attach() function makes database objects visible in the R

environment.

• The first use attaches (or reattaches) the rquser schema.

• Recall that the ore.sync() function synchronizes the R environment with the

database, whereas the ore.attach() function simply makes schema objects visible to

the R environment search path.

• In the second use, the rquser schema is attached and placed at the second

position in the environment search path.

The ore.get() function lets you obtain a handle to a named table in a named schema. In

the example, the handle with the name “t” may now be used to identify the ONTIME_S

19 Getting Started with ORE - 19

Page 20: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

ORE is shipped with sample code examples that are available in the samples.tar archive.

20 Getting Started with ORE - 20

Page 21: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Getting Started with ORE - 21

Page 22: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

So, in this lesson, we covered three primary topics.

• First, you learned about the prerequisites for using ORE.

• Then, you learned how to start R and ORE.

• Finally, we examined a number of basic ORE operations that enable interaction

between R and Oracle Database.

Getting Started with ORE - 22

Page 23: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

You’ve just completed “Getting Started with ORE”. Please move on to the next lesson in

the series: “R Language Basics”.

Getting Started with ORE - 23

Page 24: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

Getting Started with ORE - 24

Page 25: paced lesson entitled “Getting Started with ORE.” This ... · outline to display its contents. Transcript Click the Transcript tab to view the audio transcript for each slide.

25 Getting Started with ORE - 25