ore.doEval
関数は、入力関数によって生成されたデータを使用して指定された入力関数を実行します。ore.frame
オブジェクトまたはシリアライズRオブジェクトをore.object
オブジェクトとして返します。
ore.doEval
関数の構文は次のとおりです。
ore.doEval(FUN, ..., FUN.VALUE = NULL, FUN.NAME = NULL, FUN.OWNER = NULL)
関連項目:
関数ore.doEval
の引数の詳細は、「スクリプトを実行する関数の引数」を参照してください。
例6-6 ore.doEval関数の使用方法
この例では、RandomRedDots
によって、1つの引数を取り、2つの列を持つdata.frame
オブジェクトを返し、100個のランダム標準値を表示する関数を取得します。次に、ore.doEval
関数を呼び出して、RandomRedDots
function
オブジェクトを渡します。イメージがクライアントに表示されますが、これはRandomRedDots
関数を実行したデータベース・サーバーのRエンジンによって生成されます。
RandomRedDots <- function(divisor = 100){ id<- 1:10 plot(1:100, rnorm(100), pch = 21, bg = "red", cex = 2 ) data.frame(id=id, val=id / divisor) } ore.doEval(RandomRedDots)例6-6のリスト
R> RandomRedDots <- function(divisor = 100){ + id<- 1:10 + plot(1:100, rnorm(100), pch = 21, bg = "red", cex = 2 ) + data.frame(id=id, val=id / divisor) + } R> ore.doEval(RandomRedDots) id val 1 1 0.01 2 2 0.02 3 3 0.03 4 4 0.04 5 5 0.05 6 6 0.06 7 7 0.07 8 8 0.08 9 9 0.09 10 10 0.10
例6-7 オプションの引数を指定したore.doEval関数の使用方法
doEval
関数のオプションの引数として入力関数に引数を指定できます。この例では、RandomRedDots
関数のdivisor
引数をオーバーライドするオプションの引数を指定してdoEval
関数を呼び出します。
ore.doEval(RandomRedDots, divisor = 50)例6-7のリスト
R> ore.doEval(RandomRedDots, divisor = 50) id val 1 1 0.02 2 2 0.04 3 3 0.06 4 4 0.08 5 5 0.10 6 6 0.12 7 7 0.14 8 8 0.16 9 9 0.18 10 10 0.20 # The graph displayed by the plot function is not shown.
例6-8 FUN.NAME引数を指定したore.doEval関数の使用方法
入力関数がOracle R EnterpriseのRスクリプト・リポジトリに格納されている場合は、FUN.NAME
引数を指定してore.doEval
関数を呼び出すことができます。この例ではまず、myRandomRedDots
という名前のスクリプトがRスクリプト・リポジトリに含まれないようにするために、ore.scriptDrop
を呼び出します。この例では、例6-6のRandomRedDots
関数をmyRandomRedDots
という名前でリポジトリに追加します。この例では、ore.doEval
関数を呼び出し、myRandomRedDots
を指定します。結果は変数res
に割り当てられます。
RandomRedDots
関数の戻り値はdata.frame
ですが、この例では、ore.doEval
関数はore.object
オブジェクトを返します。data.frame
オブジェクトを取得するために、ore.pull
を呼び出して結果をクライアントのRセッションにプルします。
ore.scriptDrop("myRandomRedDots") ore.scriptCreate("myRandomRedDots", RandomRedDots) res <- ore.doEval(FUN.NAME = "myRandomRedDots", divisor = 50) class(res) res.local <- ore.pull(res) class(res.local)例6-8のリスト
R> ore.scriptDrop("myRandomRedDots") R> ore.scriptCreate("myRandomRedDots", RandomRedDots) R> res <- ore.doEval(FUN.NAME = "myRandomRedDots", divisor = 50) R> class(res) [1] "ore.object" attr(,"package") [1] "OREembed" R> res.local <- ore.pull(res) R> class(res.local) [1] "data.frame"
例6-9 FUN.VALUE引数を指定したore.doEval関数の使用方法
doEval
関数でore.object
ではなくore.frame
オブジェクトが返されるようにするには、この例に示すように、引数FUN.VALUE
を使用して結果の構造を指定します。
res.of <- ore.doEval(FUN.NAME="myRandomRedDots", divisor = 50, FUN.VALUE= data.frame(id = 1, val = 1)) class(res.of)例6-9のリスト
R> res.of <- ore.doEval(FUN.NAME="myRandomRedDots", divisor = 50, + FUN.VALUE= data.frame(id = 1, val = 1)) R> class(res.of) [1] "ore.frame" attr(,"package") [1] "OREbase"
例6-10 ore.connect引数を指定したdoEval関数の使用方法
この例では、特殊なオプションの引数ore.connect
を使用して埋込みR関数でデータベースに接続することにより、データストアに格納されているオブジェクトを使用できるようにする方法を示します。この例では、RandomRedDots2
関数オブジェクト(例6-6のRandomRedDots
関数と似ているが、RandomRedDots2
関数はデータストア名を指定する引数を取る)を作成します。この例では、myVar
変数を作成して、datastore_1
という名前のデータストアに保存します。次に、doEval
関数を呼び出してデータストア名を渡し、TRUE
に設定したore.connect
制御引数を渡します。
RandomRedDots2 <- function(divisor = 100, datastore.name = "myDatastore"){ id <- 1:10 plot(1:100, rnorm(100), pch = 21, bg = "red", cex = 2 ) ore.load(datastore.name) # Contains the numeric variable myVar. data.frame(id = id, val = id / divisor, num = myVar) } myVar <- 5 ore.save(myVar, name = "datastore_1") ore.doEval(RandomRedDots2, datastore.name = "datastore_1", ore.connect = TRUE)例6-10のリスト
R> RandomRedDots2 <- function(divisor = 100, datastore.name = "myDatastore"){ + id <- 1:10 + plot(1:100, rnorm(100), pch = 21, bg = "red", cex = 2 ) + ore.load(datastore.name) # Contains the numeric variable myVar. + data.frame(id = id, val = id / divisor, num = myVar) + } R> ore.doEval(RandomRedDots2, datastore.name = "datastore_1", ore.connect = TRUE) id val num 1 1 0.01 5 2 2 0.02 5 3 3 0.03 5 4 4 0.04 5 5 5 0.05 5 6 6 0.06 5 7 7 0.07 5 8 8 0.08 5 9 9 0.09 5 10 10 0.10 5 # The graph displayed by the plot function is not shown.
例6-11 ora.type属性の使用方法
この例では、ora.type
属性を使用して、FUN.VALUE
引数で指定されたdata.frame
オブジェクト内の列にデータベース・データ型のCLOBおよびBLOBを指定する方法を示します。
eval1 <- ore.doEval(function() "Hello, world") eval2 <- ore.doEval(function() data.frame(x = "Hello, world", stringsAsFactors = FALSE)) eval3 <- ore.doEval(function() data.frame(x = "Hello, world", stringsAsFactors = FALSE), FUN.VALUE = data.frame(x = character(), stringsAsFactors = FALSE)) out.df <- data.frame(x = character(), y = raw(), stringsAsFactors = FALSE) attr(out.df$x, "ora.type") <- "clob" attr(out.df$y, "ora.type") <- "blob" eval4 <- ore.doEval(function() { res <- data.frame(x = "Hello, world",stringsAsFactors = FALSE) res$y[[1L]] <- charToRaw("Hello, world") res}, FUN.VALUE = out.df) eval1 class(eval1) # ore.object eval2 class(eval2) # ore.object eval3 class(eval3) # ore.frame eval4$x rawToChar(ore.pull(eval4$y))
例6-11のリスト
R> eval1 <- ore.doEval(function() "Hello, world") R> eval2 <- + ore.doEval(function() + data.frame(x = "Hello, world", stringsAsFactors = FALSE)) R> eval3 <- + ore.doEval(function() + data.frame(x = "Hello, world", stringsAsFactors = FALSE), + FUN.VALUE = + data.frame(x = character(), stringsAsFactors = FALSE)) R> out.df <- data.frame(x = character(), y = raw(), stringsAsFactors = FALSE) R> attr(out.df$x, "ora.type") <- "clob" R> attr(out.df$y, "ora.type") <- "blob" R> eval4 <- + ore.doEval(function() { + res <- data.frame(x = "Hello, world",stringsAsFactors = FALSE) + res$y[[1L]] <- charToRaw("Hello, world") + res}, + FUN.VALUE = out.df) R> eval1 [1] "Hello, world" R> class(eval1) [1] "ore.object" attr(,"package") [1] "OREembed" R> eval2 x 1 Hello, world R> class(eval2) [1] "ore.object" attr(,"package") [1] "OREembed" R> eval3 x 1 Hello, world Warning message: ORE object has no unique key - using random order R> class(eval3) [1] "ore.frame" attr(,"package") [1] "OREbase" R> eval4$x [1] "Hello, world" Warning message: ORE object has no unique key - using random order R> rawToChar(ore.pull(eval4$y)) [1] "Hello, world" Warning message: ORE object has no unique key - using random order