[R-pkg-devel] develop package with lots of tcltk in it
Dirk Eddelbuettel
edd at debian.org
Thu May 12 17:30:50 CEST 2016
On 11 May 2016 at 12:56, Dalthorp, Daniel wrote:
| I have an R/tcltk application that is designed for use primarily by people
| who don't know R and don't care to learn much about it. I'd like users to
| be able to use the software with a bare minimum interaction with R.
|
| Although the application has some 15000 lines of code in a couple dozen .R
| files, in essence I don't think it's much more than an elaborate version of
| the following:
|
| library(tcltk)
| tt <- tktoplevel() # a required container for tk objects (textboxes,
| radiobuttons, data tables, etc.)
| tk.x <- tclVar() # a tcl version of user variable x
| x.edit <- tkentry(tt, textvariable = tk.x, width = 5) # box for user to
| enter x value
| x.lbl <- tklabel(tt, text = "Enter x value: ") # a fixed label
| xcalc <- tkbutton(tt, text = "Calculate", command = function()
| tkmessageBox(message = tclvalue(tk.x))) # button that prints x to R console
| tkgrid(x.lbl, x.edit, xcalc) # a function that puts the textbox, label, and
| button onto the tk window
|
| The following doesn't work:
| # tt, x.edit, x.lbl, xcalc all seem to me like an R objects that will not
| be modified, so I tried
| devtools::use_data(tt, x.edit, x.lbl, xcalc, internal = F, overwrite=T) #
| (after defining them)
| # tk.x is a variable that I want to assign a value to at the beginning, but
| user can later change the value:
| devtools::use_data(tt, x.edit, x.lbl, xcalc, internal = F, overwrite=T)
|
| The following does work, but it is not a good solution:
| (1) define working directory as package/data
| (2) create new tk windows via tkbutton commands = function()
| source(filename)
| This forces the user to use a pre-defined working directory. My application
| fills that wd with several hundred functions and variables. If user changes
| wd or changes values of variables that my app needs, the program crashes.
|
| Any help would be greatly appreciated!
I haven't seen the obvious stated: Have you looked into creating a package?
It can contain as much tcl/tk support code as you like, etc pp. And as you
state you have '15000 lines of code in a couple dozen .R files' you are well
passed the point where a package really is the best choice.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the R-package-devel
mailing list