3.2.3.5.6 データストアからのオブジェクトのリストア
ore.load
関数は、データストアに保存したRオブジェクトをRグローバル環境(.GlobalEnv
)にリストアします。
この関数は、リストアされるオブジェクトの名前を含む文字列ベクターを返します。
保存されたすべてのオブジェクトをロードするか、list
引数を使用してロードするオブジェクトを指定できます。envir
引数を使用すると、オブジェクトをロードする環境を指定できます。
例3-22 データストアからオブジェクトをリストアするためのore.load関数の使用方法
この例では、ore.load
関数を使用して、例3-20で作成されたデータストアからオブジェクトをリストアする方法を示します。この例は、その例と同じRセッションで実行されます。
# List the R objects. ls() # List the datastores. ore.datastore() # Delete the x and z objects. rm(x, z) ls() # Restore all of the objects in datastore ds2. ore.load("ds2") ls() # After ending the R session and starting another session. ls() # The datastore objects persist between sessions. ore.datastore() # Restore some of the objects from datastore ds1. ore.load("ds1", list = c("df1", "df2", "iris_of")) ls()例3-22のリスト
R> # List the R objects.
R> ls()
[1] "df1" "df2" "iris_of" "x" "y" "z"
R>
R> # List the datastores.
R> ore.datastore()
datastore.name object.count size creation.date description
1 another_ds 3 1243 2014-07-24 13:31:56 For pattern mattching
2 dfobj 2 656 2014-07-24 13:31:46 df objects
3 ds1 4 3162 2014-07-24 13:25:17 My datastore
4 ds2 2 1111 2014-07-24 13:27:26 only x
R>
R> # Delete the x and z objects.
R> rm(x, z)
R> ls()
[1] "df1" "df2" "iris_of" "y"
R>
R> # Restore all of the objects in datastore ds2.
R> ore.load("ds2")
[1] "x" "z"
R>
R> ls()
[1] "df1" "df2" "iris_of" "x" "y" "z"
R>
R> # After ending the R session and starting another session.
R> ls()
character(0)
R> # The datastore objects persist between sessions.
R> ore.datastore()
datastore.name object.count size creation.date description
1 another_ds 3 1243 2014-07-24 13:31:56 For pattern mattching
2 dfobj 2 656 2014-07-24 13:31:46 df objects
3 ds1 4 3162 2014-07-24 13:25:17 My datastore
4 ds2 2 1111 2014-07-24 13:27:26 only x
R> # Restore some of the objects from datastore ds1.
R> ore.load("ds1", list = c("df1", "df2", "iris_of"))
[1] "df1" "df2" "iris_of"
R> ls()
[1] "df1" "df2" "iris_of"
親トピック: データベースでのRオブジェクトの保存および管理