3.2.3.5.5 データストアのコンテンツに関する情報の取得

ore.datastore関数およびore.datastoreSummary関数を使用することで、現行のユーザー・スキーマのデータストアに関する情報を取得できます。

ore.datastore関数を使用して、データストアに関する基本的な情報をリストできます。特定のタイプのデータストアに関する情報を取得するには、オプションの文字列引数typeを使用できます。typeの有効な値は次のとおりです。

  • 現行のセッション・ユーザーが作成したデータストアをリストするuser。これはデフォルト値です。

  • 現行のセッション・ユーザーが他のユーザーに読取りアクセス権を付与できないデータストアをリストするprivate

  • 現行のセッション・ユーザーが読取りアクセス権を持っているすべてのデータストアをリストするall

  • 現行のセッション・ユーザーが他のユーザーに読取り権限を付与できるデータストアをリストするgrantable

  • 現行のセッション・ユーザーが他のユーザーに読取り権限を付与したデータストアをリストするgrant

  • 他のユーザーによって現行のセッション・ユーザーに読取り権限が付与されたデータストアをリストするgranted

タイプを指定しなかった場合、関数ore.datastoreは、データストア名、データストア内のオブジェクト数、データストアのサイズ、作成日および説明に対応する列を含むdata.frameオブジェクトを返します。行は、列datastore.nameによってアルファベット順にソートされます。タイプを指定した場合、この関数は、指定したタイプの列を含むdata.frameを返します。

名前または正規表現パターンを使用してデータストアを検索できます。

ore.datastoreSummary関数は、接続されているデータベースのユーザー・スキーマにあるデータストアに保存されたRオブジェクトに関する情報を返します。この関数は、data.frameを返します。オブジェクト名、オブジェクト・クラス、オブジェクトのサイズおよびオブジェクトの長さ(vectorの場合)または行および列の数(data.frameオブジェクトの場合)に対応する列を含みます。これは、1つの必須の引数としてデータストアの名前を取りますが、オプションの引数としてデータストアの所有者を取ることもできます。

例3-20 ore.datastore関数の使用方法

この例では、ore.datastore関数の使用方法を示します。

# Create some R objects.df1 <- data.frame(x1 = 1:5, y1 = letters[1:5])
df2 <- data.frame(x2 = 5:1, y2 = letters[11:15])
iris_of <- ore.push(iris)

# Create a database table and an OML4R proxy object for the table.
ore.drop("AIRQUALITY")
ore.create(airquality, table = "AIRQUALITY")
                                                                            
# Save the objects to a datastore named ds1 and supply a description.
ore.save(AIRQUALITY, list = ls(), name = "ds1", description = "My private datastore")

# Create some more objects.
x <- stats::runif(20) # x is an object of type numeric.
y <- list(a = 1, b = TRUE, c = "hoopsa")
z <- ore.push(x) # z is an object of type ore.numeric.

# Create other datastores.
ore.save(x, y, name = "ds2", description = "x and y")
ore.save(df1, df2, name = "dfobj", description = "df objects")
ore.save(x, y, z, name = "another_ds", description = "For pattern matching")

# List all of the datastore objects.
ore.datastore()

# List the specified datastore.
ore.datastore("ds1")

# List the datastore objects with names that include "ds".
ore.datastore(pattern = "ds")

この例のリスト

R> # Create some R objects.
R> df1 <- data.frame(x1 = 1:5, y1 = letters[1:5])
R> df2 <- data.frame(x2 = 5:1, y2 = letters[11:15])
R> iris_of <- ore.push(iris)
R> 
R> # Create a database table and an OML4R proxy object for the table.
R> ore.drop("AIRQUALITY")
R> ore.create(airquality, table = "AIRQUALITY")
R>                                                                             
R> # Save the objects to a datastore named ds1 and supply a description.
R> ore.save(AIRQUALITY, list = ls(), name = "ds1", description = "My private datastore")
R>
R> # Create some more objects.
R> x <- stats::runif(20) # x is an object of type numeric.
R> y <- list(a = 1, b = TRUE, c = "hoopsa")
R> z <- ore.push(x) # z is an object of type ore.numeric.
R>
R> # Create other datastores.
R> ore.save(x, y, name = "ds2", description = "x and y")
R> ore.save(df1, df2, name = "dfobj", description = "df objects")
R> ore.save(x, y, z, name = "another_ds", description = "For pattern matching")
R> 
R> # List all of the datastore objects.
R> ore.datastore()
  datastore.name object.count size       creation.date          description
1     another_ds            3 1284 2017-04-21 16:08:57 For pattern matching
2          dfobj            2  656 2017-04-21 16:08:38           df objects
3            ds1            4 3439 2017-04-21 16:03:55 My private datastore
4            ds2            2  314 2017-04-21 16:04:32              x and y

R> # List the specified datastore.
R> ore.datastore("ds1")
  datastore.name object.count size       creation.date          description
1            ds1            4 3439 2017-04-21 16:03:55 My private datastore

R> # List the datastore objects with names that include "ds".
R> ore.datastore(pattern = "ds")
  datastore.name object.count size       creation.date          description
1     another_ds            3 1284 2017-04-21 16:08:57 For pattern matching
2            ds1            4 3439 2017-04-21 16:03:55 My private datastore
3            ds2            2  314 2017-04-21 16:04:32              x and y

例3-21 ore.datastoreSummary関数の使用方法

この例では、ore.datastoreSummary関数の使用方法を示します。この例では、前の例で作成したデータストアを使用します。

ore.datastoreSummary("ds1")
ore.datastoreSummary("ds2")

この例のリスト

R> ore.datastoreSummary("ds1")
  object.name      class size length row.count col.count
1  AIRQUALITY  ore.frame 1213      6        NA         6
2         df1 data.frame  328      2         5         2
3         df2 data.frame  328      2         5         2
4     iris_of  ore.frame 1570      5        NA         5
R> ore.datastoreSummary("ds2")
  object.name   class size length row.count col.count
1           x numeric  182     20        NA        NA
2           y    list  132      3        NA        NA