[Rd] problem with fix() called from Rcmdr

John Fox jfox at mcmaster.ca
Mon Nov 3 00:47:30 MET 2003

Dear list members,

I and my students have encountered an intermittent problem using the Rcmdr 
package (version 0.9-0) under Windows (with the SDI). The problem occurs 
both in versions 1.7.1 and 1.8.0 of R.

The problem seems to occur only in the following context: The "Edit data 
set" button is pressed in the Rcmdr GUI. This executes the fix() function 
on the active data frame, bringing up a data editor window. After changing 
variable names in the data editor, the editor is closed by the user. This 
causes the active data frame to be detached and re-attached. That is, this 
is what happens when things work normally. Frequently, however, Rgui.exe 
crashes at this point, reporting a "program error."

I suspect that there some kind of timing problem, but before I experiment 
further, I wonder whether anyone has any more specific ideas.

To be supply some more details, the "Edit data set" button executes the 
following code:

     onEdit <- function(){
         command <- paste("fix(", .activeDataSet, ")", sep="")

where .activeDataSet is a (global) character variable containing the name 
of the "active" data frame, logger() just echoes the command to the R console

logger <- function(command){
     if (tclvalue(.logCommands) == "1") {
         tkinsert(.log, "end", paste(command,"\n", sep=""))
         tkyview.moveto(.log, 1)
     lines <- strsplit(command, "\n")[[1]]
     for (line in lines) cat(paste("\nR-cmdr>", line, "\n"))

and JustDoIt() is defined as follows:

justDoIt <- function(command) {
     result <- try(eval(parse(text=command), envir=.GlobalEnv), silent=TRUE)
     if (class(result)[1] ==  "try-error"){
             strsplit(result, ":")[[1]][2]), icon="error")

The function activeDataSet() has the following definition (but I doubt that 
the problem is there, since Rcmdr uses this function a lot and I've not 
observed a problem in any other context):

activeDataSet <- function(dsname){
     if (missing(dsname)) {
         if (is.null(.activeDataSet)){
             tkmessageBox(message="There is no active data set.", 
icon="error", type="ok")
         else return(.activeDataSet)
     if (!is.data.frame(get(dsname, envir=.GlobalEnv))){
         tkmessageBox(message=paste(dsname, " is not a data frame and 
cannot be attached.",
             sep=""), icon="error", type="ok")
     if (!is.null(.activeDataSet) && (tclvalue(.attachDataSet) == "1")
         && (length(grep(.activeDataSet, search())) !=0)) {
         detach(pos = match(.activeDataSet, search()))
         logger(paste("detach(", .activeDataSet, ")", sep=""))
     assign(".activeDataSet", dsname, envir=.GlobalEnv)
     assign(".variables", listVariables(), envir=.GlobalEnv)
     assign(".numeric", listNumeric(), envir=.GlobalEnv)
     assign(".factors", listFactors(), envir=.GlobalEnv)
     assign(".twoLevelFactors", listTwoLevelFactors(), envir=.GlobalEnv)
     tclvalue(.dataSetName) <- paste(.activeDataSet, " ")
     tkconfigure(.dataSetLabel, fg="blue")
     if (tclvalue(.attachDataSet) == "1"){
         attach(get(dsname, envir=.GlobalEnv), name=dsname)
         logger(paste("attach(", dsname, ")", sep=""))

Any help would be greatly appreciated.

John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox

More information about the R-devel mailing list