2016-10-24 9 views
2

基本的にビルド、トレーニング、さらにはIC50値の予測に使用される作業用Rコードがありました。 私は動作しているGUIを持っています。GUIを含むRパッケージを作成する

# Load the packages 
library(gWidgets) 
library(gWidgetsRGtk2) 
library(tcltk) 
library(data.table) 
library(cluster) 
library(e1071) 
library(caret) 
options(guiToolkit="RGtk2") 

#main GUI code 
win=gwindow("Naive Bayes Tool for IC50 Prediction") 
size(win)<-c(1000,600) 
group<-ggroup(cont=win) 
left_group<-ggroup(cont=group,horizontal=FALSE) 
right_group<-ggroup(cont=group,horizontal=FALSE) 
txtOutput = gtext("", cont = group, expand = TRUE) 
frame<-gframe("Bankruptcy Tool",cont=left_group,horizontal=FALSE,) 
# size(frame)<-c(300,350) 
tbl=glayout(cont=frame) 
# To Browse the file 
tbl[2,1] = gfilebrowse (text = "Select Training File...", type = "open", quote = FALSE, 
         filter = list("Text File" = list(patterns = c("*.csv"))), container = tbl) 
tbl[3,1] = gbutton("Upload File",cont=tbl,handler=uploadfile) 
enabled(tbl[3,1]) <- FALSE 

#Function to upload file 
uploadfile<-function(h,...){ 
    bipsdata <- read.csv(svalue(tbl[2,1])) 
    inputdata<-data.frame(bipsdata) 
    normo2<-capture.output(head(inputdata)) 
    str.split <- strsplit(normo2, "\\s+") 
    str.joined <- sapply(str.split,function(bits) paste(bits,collapse='\t')) 
    insert(txtOutput,normo2,font.attr = c(family="monospace")) 
    gmessage("Data Uploaded!!!", color="blue") 
} 
addHandlerChanged(tbl[2,1], handler=function(h,...) { 
    val <-svalue(tbl[2,1]) 
    # data1<-data.frame(val) 
    if(!is.na(val)) { 
    filename <<- val 
    #  df1 = read.csv(filename, header = TRUE) 
    enabled(tbl[3,1]) <- TRUE 
    } 
}) 
addHandlerChanged(tbl[3,1], handler=uploadfile) 
# Creating a frame for prediction of clustering results 
frame3<-gframe("Prediction",cont=left_group,horizontal=FALSE, font.attr=list(style="bold")) 

ARatings<- gbutton("Submit and Build Model",cont=frame3, handler=Arat) 
Enter<-glabel("Enter the Input Data:-",cont=frame3) 

IR1= gedit("AATS3e", cont=frame3,coerce.with=as.numeric) 
MR2= gedit("MATS3c", cont=frame3,coerce.with=as.numeric) 
FF3= gedit("MATS4c", cont=frame3,coerce.with=as.numeric) 
CR4= gedit("MATS3e", cont=frame3,coerce.with=as.numeric) 
CO5= gedit("MATS3s", cont=frame3,coerce.with=as.numeric) 
OP6= gedit("GATS7c", cont=frame3,coerce.with=as.numeric) 
Class1= gedit("Class", cont=frame3) 
Predict<-gbutton("Predict Model", cont=frame3, handler=AratSave) 


# Function to Train Data 
Arat<-function(ARatings,h,...) 
{ 
    library(data.table) 
    library(e1071) 
    bipsdata<-read.csv(filename) 
    inputdata<-data.frame(bipsdata) 
    naive.model<-naiveBayes(Class~.,inputdata,probability=TRUE) 
    result1<-print(naive.model) 
    normo<-data.frame(result1) 
    normo1<-capture.output(naive.model) 
    insert(txtOutput,normo1, font.attr = c(family="monospace")) 
} 

#Function to Predict Bankruptcy 
AratSave<-function(ARatings, h,...) 
{ 
    library(data.table) 
    library(e1071) 
    bipsdata<-read.csv(filename) 
    inputdata<-data.frame(bipsdata) 
    naive.model<-naiveBayes(Class~AATS3e+MATS3c+MATS4c+MATS3e+MATS3s+GATS7c,inputdata,probability=TRUE) 

    AATS3e<-as.numeric(svalue(IR1)) 
    MATS3c<-as.numeric(svalue(MR2)) 
    MATS4c<-as.numeric(svalue(FF3)) 
    MATS3e<-as.numeric(svalue(CR4)) 
    MATS3s<-as.numeric(svalue(CO5)) 
    GATS7c<-as.numeric(svalue(OP6)) 
    Class<-svalue(Class1) 

    Newinput<-data.frame(cbind(AATS3e,MATS3c,MATS4c,MATS3e,MATS3s,GATS7c)) 
    print(Newinput) 
    results<-predict(naive.model,Newinput) 
    result12<-print(results) 
    normo11<-data.frame(result12) 
    normo1<-capture.output(result12) 
    insert(txtOutput,normo1, font.attr = c(family="monospace")) 

    #Comparing Accuracy 
    #code is having error because the predicted result is only one column but the model has many columns. 
    xtab<-table(pred=results,true=svm.model) 
    cofusionMatrix(xtab) 
    y<-print(confusionMatrix(xtab)) 
    normo12<-capture.output(y) 
    insert(txtOutput,normo12, font.attr = c(family="monospace")) 
} 

Rパッケージを作成しようとしました。 説明ファイルでライブラリをインポートする手順に従いました。 が解決策を見つけることができませんでした。私を助けてください。 あなたはgwindow iはDESCRIPTIONファイルにインポートライブラリから呼び出される関数で見ることができるようにエラーが発生しました。この

Updating IC50 documentation 
Loading IC50 
Error in eval(expr, envir, enclos) (from IC50.r#7) : could not find function "gwindow" 
Calls: suppressPackageStartupMessages ... withr_with_dir -> force -> source_many -> source_one -> eval -> eval 
Execution halted 

Exited with status 1. 

のようなものです。しかし、それは動作していません。

説明ファイルは次のとおりです。

Package: IC50 
Type: Package 
Title: Predicts IC50 
Version: 0.1.0 
Author: Who wrote it 
Maintainer: Who to complain to <[email protected]> 
Description: More about what it does (maybe more than one line) 
License: What license is it under? 
LazyData: TRUE 
RoxygenNote: 5.0.1 
Imports: gWidgets,gWidgetsRGtk2,tcltk,data.table,cluster,e1071,caret 
Depends: R (>= 3.0),gWidgets,gWidgetsRGtk2,tcltk,data.table,cluster,e1071,caret, cluster 
     , e1071, 
     ggplot2, gplots, grid, gtools, 
     gWidgetsRGtk2, nnet, 
Suggests: pmml (>= 1.2.13), bitops, colorspace, ada, amap, arules, 
     arulesViz, biclust, cairoDevice, cba, cluster, corrplot, descr, 
     doBy, dplyr, e1071, ellipse, fBasics, foreign, fpc, gdata, 
     ggdendro, ggplot2, gplots, graph, grid, gridExtra, gtools, 
     gWidgetsRGtk2, hmeasure, Hmisc, kernlab, Matrix, mice, nnet, 
     odfWeave, party, playwith, plyr, psych, randomForest, RBGL, 
     RColorBrewer, readxl, reshape, rggobi, RGtk2Extras, ROCR, 
     RODBC, rpart, rpart.plot, SnowballC, stringr, survival, 
     timeDate, tm, verification, wskm, XML, pkgDepTools, Rgraphviz 
NeedsCompilation: Yes 
LazyData: yes 

このエラー

==> devtools::document(roclets=c('rd', 'collate', 'namespace')) 

Updating IC50 documentation 
Loading IC50 

(Rterm.exe:732): Gtk-CRITICAL **: gtk_table_attach: assertion `child->parent == NULL' failed 
First time using roxygen2. Upgrading automatically... 
Error: Missing name at IC50.r:6 
Execution halted 

Exited with status 1. 

が更新輸入品との記述ファイルを追加されます。 は次のように説明ファイルを作成しました。メインRファイルのFuntionをライブラリとして呼び出すように追加しました。

Description: Utilizes the Naive Bayes Classifier for Drug Prediction. 
License: Public 
LazyData: TRUE 
RoxygenNote: 5.0.1 
Imports: gWidgets,gWidgetsRGtk2,tcltk,data.table,cluster,e1071,caret,gWidgetstcltk 
Depends: R (>= 3.2),gWidgets,gWidgetsRGtk2,tcltk,data.table,cluster,e1071,caret, cluster 
     ,e1071,gWidgetstcltk, ggplot2, gplots, grid, gtools, 
     gWidgetsRGtk2, nnet, 
Suggests: pmml (>= 1.2.13), bitops, colorspace, ada, amap, arules, 
     arulesViz, biclust, cairoDevice, cba, cluster, corrplot, descr, 
     doBy, dplyr, e1071, ellipse, fBasics, foreign, fpc, gdata, 
     ggdendro, ggplot2, gplots, graph, grid, gridExtra, gtools, 
     gWidgetsRGtk2, hmeasure, Hmisc, kernlab, Matrix, mice, nnet, 
     odfWeave, party, playwith, plyr, psych, randomForest, RBGL, 
     RColorBrewer, readxl, reshape, rggobi, RGtk2Extras, ROCR, 
     RODBC, rpart, rpart.plot, SnowballC, stringr, survival, 
     timeDate, tm, verification, wskm, XML, pkgDepTools, Rgraphviz 
NeedsCompilation: Yes 
LazyData: yes 
+0

あなたのNAMESPACEの外観は何ですか? –

+0

これは名前空間にあったものです。 exportPattern( "^ [[alpha:]] +") –

+0

なぜ 'roxygen2'タグですか?あなたは 'roxygen'コメントを使用していません。 – hrbrmstr

答えて

1

更新されたインポートファイルを追加しました。説明ファイルは次のようになりました。メインRファイルのFuntionをライブラリとして呼び出すように追加しました。

Description: Utilizes the Naive Bayes Classifier for Drug Prediction. 
License: Public 
LazyData: TRUE 
RoxygenNote: 5.0.1 
Imports: gWidgets,gWidgetsRGtk2,tcltk,data.table,cluster,e1071,caret,gWidgetstcltk 
Depends: R (>= 3.2),gWidgets,gWidgetsRGtk2,tcltk,data.table,cluster,e1071,caret, cluster 
     ,e1071,gWidgetstcltk, ggplot2, gplots, grid, gtools, 
     gWidgetsRGtk2, nnet, 
Suggests: pmml (>= 1.2.13), bitops, colorspace, ada, amap, arules, 
     arulesViz, biclust, cairoDevice, cba, cluster, corrplot, descr, 
     doBy, dplyr, e1071, ellipse, fBasics, foreign, fpc, gdata, 
     ggdendro, ggplot2, gplots, graph, grid, gridExtra, gtools, 
     gWidgetsRGtk2, hmeasure, Hmisc, kernlab, Matrix, mice, nnet, 
     odfWeave, party, playwith, plyr, psych, randomForest, RBGL, 
     RColorBrewer, readxl, reshape, rggobi, RGtk2Extras, ROCR, 
     RODBC, rpart, rpart.plot, SnowballC, stringr, survival, 
     timeDate, tm, verification, wskm, XML, pkgDepTools, Rgraphviz 
NeedsCompilation: Yes 
LazyData: yes 
関連する問題