2016-10-24 2 views
2

Ich hatte einen funktionierenden R-Code, der im Grunde verwendet wird, um einige IC50-Werte zu erstellen, zu trainieren und auch vorherzusagen. Ich habe die funktionierende GUI.Erstellen von R-Paket mit GUI

# 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")) 
} 

Ich habe versucht, R-Paket zu erstellen. Schritte zum Importieren der Bibliotheken in der Datei DESCRIPTION gefolgt. aber konnte die Lösung nicht finden. Bitte hilf mir. Der Fehler ist wie dieser

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. 

Wie Sie die gwindow sehen eine Funktion ist, die aus der Bibliothek aufgerufen werden soll i in Beschreibungsdatei importiert. Aber es funktioniert nicht.

Die Beschreibungsdatei ist wie folgt.

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 

Dies ist der Fehler

==> 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. 

Added der Beschreibungsdatei mit aktualisierten Importen. funktioniert jetzt gut Beschreibungsdatei wie folgt. und fügte auch die Funtion in der Haupt-R-Datei hinzu, um sie als Bibliothek aufzurufen.

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

Wie sieht Ihr NAMESPACE aus? –

+0

Dies ist, was im Namensraum war. exportPattern ("^ [[: alpha:]] +") –

+0

Warum das 'roxygen2'-Tag? Du verwendest keine 'roxygen' Kommentare. – hrbrmstr

Antwort

1

Die BESCHREIBUNG Datei mit aktualisierten Importen hinzugefügt. funktioniert jetzt gut Beschreibungsdatei wie folgt. und fügte auch die Funtion in der Haupt-R-Datei hinzu, um sie als Bibliothek aufzurufen.

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