r - gWidgets packaging -
r - gWidgets packaging -
i've made gui r simulation , bound function in it's own .r file in r folder of packages directory:
gui <- function(){ mainwin <- gwindow("speear - simulation of plant-pathogen effectors in evolutionary arms races") introtext <- glabel("speear - simulation of plant-pathogen effectors in evolutionary arms races, version 1.1 bundle maintained ben ward. <b.ward@uea.ac.uk>", cont = mainwin, markup=true) moretext <- glabel("to begin, edit settings of simulation. settings stored in matrix , can read in .r object files. help , documentation click help button, or utilize r's documentation system.", cont=mainwin) main_grp <- ggroup(container = mainwin) settings_grp <- ggroup(container = main_grp, horizontal=false) settings_frame <- gframe("settings", cont=settings_grp) editsetbutton <- gbutton("edit settings", cont=settings_frame, handler=function(h,...){ fix(settings) }) savesetbutton <- gbutton("write settings file", cont=settings_frame, handler=function(h,...){ settingsfilename <- ginput("please come in filename save settings matrix to. bear in mind save current working directory of r.",text="", title="filename?", icon="question") save(settings, file=settingsfilename) }) loadsetbutton <- gbutton("load settings", cont=settings_frame, handler=function(h,...){ fname <- gfile(test="choose file", type="open", action="print", handler = function(h,...){ do.call(h$action, list(h$file)) } ) load(fname)}) runhelp_grp <- ggroup(cont=main_grp) runsimbutton <- gbutton("run simulation!", cont=runhelp_grp, expand=true, handler=function(h,...){ run.sim(settings) }) helpbutton <- gbutton("help", cont=runhelp_grp, handler=function(h,...){ visible(helpwin) <- true }) addspring(runhelp_grp) helpwin <- gwindow("help pages", visible=false) helpwidget <- ghelp(container = helpwin, expand=true) add(helpwidget, list(topic="values.gen", package="speear")) add(helpwidget, list(topic="mutate", package="speear")) add(helpwidget, list(topic="evolve.probs", package="speear")) add(helpwidget, list(topic="change.expression", package="speear")) add(helpwidget, list(topic="dup.dels", package="speear")) add(helpwidget, list(topic="run.sim", package="speear")) add(helpwidget, list(topic="makesetmatrix", package="speear")) add(helpwidget, list(topic="speear", package="speear")) }
i know works running through fresh r session gwidgets , gwidgetstcltk loaded.
i've included gwidgets , gwidgetstcltk in namespace file imports. however, if build , reload bundle (i'm in rstudio), , type in console gui()
it tells me error in gui() : not find function "gwindow"
gwindow beingness first thing gui() function create window containing everything.
i tested hadn't screwed packaging of simulation, making fresh bundle containing nil simple function loads window button:
gui <- function(){ boop <- gwindow("hi world") button <- gbutton("woop!", cont=boop) }
i specified imports: gwidgets, gwidgetstcltk
in description file, built , reloaded. same error.
has else experienced this? why happen in built bundle when 2 dependencies included in namespace under imports? building , reloading bundle not show errors. whole point have gui in bundle gui function can called @ bundle loading, making easier user.
thanks, ben w. uea tsl
[edit] in response suggestion i've done:
gui <- function(){ boop <- gwindow("hi world") button <- gbutton("woop!", cont=boop) } .onload <- function(libname, pkgname){ gui() }
however i'm unfamiliar using .onload , whether have done correctly. i've read documentation , i'm trying larn how r works loading packages , namespaces, hooks etc struggle if jargon gets frequent i'm still figuring out. however, building bundle , reloading gives me new error:
error : .onload failed in loadnamespace() 'testgui', details: call: function (classes, fdef, mtable) error: unable find inherited method function ‘.gwindow’ signature ‘"null"’ error: loading failed
edit 2:
i've been working things more , think have working abstract example:
# abstract illustration of bundle function generate simulation settings: settings <- function(){ matrix(c(1:4),nrow=2,ncol=2) } # abstract illustration of internal function of simulation, simulation function # calls many times during loops: int.func <- function(x){ out <- x*2 return(out) } # abstract illustration of main simulation function, calls internal functions , saves # results r files. sim.func <- function(x){ ans <- int.func(x) save(ans, file="outtest") }
in current bundle these called console:
input <- settings() # generate settings sim. fix(input) # edit settings if desired. sim.func(input) # run sim settings defined variable 'input'
my gui below:
gui <- function(){ mainwin <- gwindow("mainwindow") button1 <- gbutton("set", cont=mainwin, handler= function(h,...){ fix(input) print("addy set") }) button2 <- gbutton("run", cont=mainwin, handler= function(h,...){ sim.func(input) print("the run done") }) savebutton <- gbutton("save settings",cont=mainwin, handler= function(h,...){ setfilename <- ginput("please come in filename") save(input, file=setfilename) }) loadutton <- gbutton("load settings", cont=mainwin, handler=function(h,...){ fname <- gfile(test="choose file", type="open", action="print", handler = function(h,...){ do.call(h$action, list(h$file)) } ) load(fname)}) }
my namespace file is:
export(gui) import(gwidgets, gwidgetstcltk)
this builds , reloads in r, , when gui()
called appears. testing it.
r function user-interface packaging gwidgets
Comments
Post a Comment