10.6.2.3 rqListEnvs関数
関数rqListEnvs
は、Oracle Autonomous Databaseで使用すると、オブジェクト・ストレージに保存されている環境をリストします。
構文
FUNCTION rqListEnvs
RETURN SYS.AnyDataSet
例
rqListEnvs
関数をコールし、存在する環境をリストする問合せを発行します。
select * from table(rqListEnvs());
出力は、次のようなものです。
NAME
----------
VALUE
--------------------------------------------------------------------------------
{"envs":[{"size":"831.5 MiB","name":"myrenv","description":"Install R forecast and ggplot2 packages","tags":{"application":"OML4R", "user":"OMLUSER"},"number_of_installed_packages":121}]}
ggplot2ライブラリをインポートし、mtcarsデータセット内のmpg変数の密度プロットを生成する、「test_ggplot2_noinp」という名前のスクリプトを作成するには、次のコードを使用します。
begin
sys.rqScriptCreate('test_ggplot2_noinp',
'function() {
library(ggplot2);
mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),
labels=c("3gears","4gears","5gears"));
gf <- qplot(mpg, data=mtcars, geom="density",
fill=gear, alpha=I(.5), main="Distribution of Gas Milage",
xlab="Miles Per Gallon", ylab="Density");
plot(gf);
res <- "hello world"
res
}',FALSE,TRUE);
end;
/
ggplot2パッケージを使用して、指定された入力データに基づいてヒストグラムを生成するスクリプトを作成するには、次のコードを使用します:
begin
sys.rqScriptCreate('test_ggplot2_inp',
'function(dat) {
library(ggplot2);
histogram <- ggplot(data=dat, aes(x=Sepal.Width)) +
geom_histogram(binwidth=0.2, color="black", aes(fill=Species)) +
xlab("Sepal Width") + ylab("Frequency") + ggtitle("Histogram of
Sepal Width")
plot(histogram);
res <- "hello world"
res
}',FALSE,TRUE);
end;
/
ggplot2ライブラリをインポートし、タイトル付きのヒストグラム・プロットを生成するスクリプトを作成するには、次のコードを使用します:
begin
sys.rqScriptCreate('test_ggplot2_idx',
'function(idx) {
library(ggplot2);
row <- iris[idx,]
histogram <- ggplot(data=row, aes(x=Sepal.Width)) +
geom_histogram(binwidth=0.2, color="black", aes(fill=Species)) +
xlab("Sepal Width") + ylab("Frequency") + ggtitle("Histogram of
Sepal Width")
plot(histogram);
res <- "hello world"
res
}',FALSE,TRUE);
end;
/
次のコードでは、SQL問合せを実行して、rqListEnvs
関数コールの結果からすべての列を取得します。これにより、指定したスクリプトおよび環境に基づいてPNG出力が生成されます。
select * from table(rqListEnvs());
出力が次のように表示されます。
NAME
----------
VALUE
-----------------------------------------------------------------
---------------
{"envs":[{"size":"823.3 MiB","name":"renv","
description":"ggplot2 package for
R","number_of_installed_packages":138,"tags":{"r":"4.0.5","applic
ation":"OML4R"}}]}