简体   繁体   English

Rapidminer中的R脚本

[英]R-Script in Rapidminer

maybe someone can help me with my problem. 也许有人可以帮助我解决我的问题。

I'm working with RapidMiner and the R-Script Operator and process a 369 x 258 occurrence matix with the following R-Script: 我正在使用RapidMiner和R-Script Operator,并使用以下R-Script处理369 x 258出现的Matix:

# rm_main is a mandatory function, 
# the number of arguments has to be the number of input ports (can be none)
rm_main = function(data)
{
total_occurrence <- colSums(data)
data_matrix <- as.matrix(data)
co_occurrence <- t(data_matrix) %*% data_matrix
library(igraph)
graph <- graph.adjacency(co_occurrence,
                          weighted = TRUE,
                          mode="undirected",
                          diag = FALSE)
tkplot(graph,
        vertex.label=names(data),
        vertex.size=total_occurrence*1,
        edge.width=E(graph)$weight*1,)

dev.copy (tk_postscript, file= '/home/knecht/r-graph.pdf')
dev.off()
}

After creating the graph the process terminates with the error message "cannot copy from the null device". 创建图形后,该过程终止,并显示错误消息“无法从空设备复制”。

So my question is, how can I print the graph in a file like postscript or png? 所以我的问题是,如何在诸如postscript或png的文件中打印图形?

Kind regard 亲切的问候

Tobias 托比亚斯

I couldn't get the R code to work outside RapidMiner so I made a couple of changes to print rather than use tkplot (which is interactive so might struggle anyway). 我无法使R代码在RapidMiner之外运行,因此我进行了一些更改以进行打印,而不是使用tkplot(这是交互式的,因此可能仍然很麻烦)。

I also added some simple data in the code to make the example reproducible. 我还在代码中添加了一些简单的数据,以使示例可以重现。

Change the location of the png file that is created to somewhere where you want to store results (RapidMiner uses temporary local folders so you have to be explicit about the location). 将创建的png文件的位置更改为要存储结果的位置(RapidMiner使用临时本地文件夹,因此您必须明确说明该位置)。

rm_main = function(data)
{
    data2 = matrix(c(1,2,3,1,2,1), nrow = 2, ncol = 3)
    total_occurrence <- colSums(data2)
    data_matrix <- as.matrix(data2)
    co_occurrence <- t(data_matrix) %*% data_matrix
    library(igraph)
    graph <- graph.adjacency(co_occurrence,
                      weighted = TRUE,
                      mode="undirected",
                      diag = FALSE)
    png('c:/temp/r-graph.png')                     
    plot(graph,
       vertex.label=names(data2),
        vertex.size=total_occurrence*1,
        edge.width=E(graph)$weight*1,)
    dev.off()
return(list(data))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM