3.2.3.5.3 データストアへのオブジェクトの保存
ore.save
関数は、1つ以上のRオブジェクトを指定されたデータストアに保存します。
デフォルトでは、OML4Rは、現行のユーザー・スキーマにデータストアを作成します。ore.save
に対して引数を指定する場合、特定のオブジェクトの名前、またはオブジェクトのリストを指定できます。データストアへの読取りアクセス権を他のユーザーに付与できるかどうかを指定できます。特定のR環境を指定して保存するオブジェクトを検索できます。overwrite
およびappend
の引数は相互に排他的です。overwrite
引数をTRUE
に設定した場合、既存のデータストアを同じ名前の別のデータストアで置換できます。append
引数をTRUE
に設定した場合、既存のデータストアにオブジェクトを追加できます。description
引数を使用すると、データストアの情報取得時に表示される説明テキストを指定できます。description
引数は、append
引数とともに使用すると機能しません。
例3-18 オブジェクトの保存およびデータストアの作成
この例では、引数の様々な組合せを使用してデータストアを作成する方法を示します。
# 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")
# List the R objects.
ls()
# List the OML4R proxy objects.
ore.ls()
# Save the proxy object and all objects in the current workspace environment
# to the 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 another datastore.
ore.save(x, y, name = "ds2", description = "x and y")
# Overwrite the contents of datastore ds2.
ore.save(x, name = "ds2", overwrite = TRUE, description = "only x")
# Append object z to datastore ds2.
ore.save(z, name = "ds2", append = TRUE)
この例のリスト
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> # List the R objects.
R> ls()
[1] "df1" "df2" "iris_of"
R>
R> # List the OML4R proxy objects.
R> ore.ls()
[1] "AIRQUALITY"
R>
R> # Save the proxy object and all objects in the current workspace environment
R> # to the datastore named ds1 and supply a description.
R> ore.save(AIRQUALITY, list = ls(), name = "ds1", description = "My 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 another datastore.
R> ore.save(x, y, name = "ds2", description = "x and y")
R>
R> # Overwrite the contents of datastore ds2.
R> ore.save(x, name = "ds2", overwrite = TRUE, description = "only x")
R>
R> # Append object z to datastore ds2.
R> ore.save(z, name = "ds2", append = TRUE)
親トピック: データベースでのRオブジェクトの保存および管理