Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
how best to debug dialog and run code
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Vincent  
View profile  
 More options Nov 13 2012, 4:46 am
From: Vincent <vincent.n...@gmail.com>
Date: Tue, 13 Nov 2012 01:46:47 -0800 (PST)
Local: Tues, Nov 13 2012 4:46 am
Subject: how best to debug dialog and run code

It took me a longgggg time to figure out a reasonably efficient way to test
and debug my code for a menu using deducer. In case this is useful to
others I am pasting a simple example below. If you source this code from
the JGR console (with Deducer loaded) you get the dialog to pop-up and can
test if the code is working as expected. If not, make changes to the code
and source again, and again, and again, as needed. If there are other,
perhaps more effective, ways to debug I'd luv to hear about them.

.olsCheckFunction <- function(state) {
if(length(state$dep) < 1)
return("Please select a dependent variable")
if(length(state$indep) < 1)
return("Please select at least one independent variable")
return("")

}

.olsRunFunction <- function(state) {

form <-paste( " ~ " , state$indep[1])
for(var in state$indep[-1])
form <- paste(form,"+",var)

cmd <- paste("summary(ols <-lm(", state$dep, form, ", data =", state$data,
"))")

execute(cmd)

}

makeOLSDialog <-function() {

# make the dialog
dialog <- new(SimpleRDialog)
dialog$setSize(500L, 400L)
dialog$setTitle("Regression")

# add a variable selector
variableSelector <-new(VariableSelectorWidget)
variableSelector$setTitle("data")
variableList <- new(VariableListWidget, variableSelector)
addComponent(dialog, variableSelector,1,450,850,10)

# add the dependent variable
dep <- new(SingleVariableWidget, "Dependent Variable", variableSelector)
dep$setTitle("dep")
addComponent(dialog, dep, 50 ,1000, 250, 500)

# add the independent variables
indep <- new(VariableListWidget, "Independent Variables", variableSelector)
indep$setTitle("indep")
addComponent(dialog, indep, 300,1000, 850, 500)

# call the check and run functions
dialog$setCheckFunction(toJava(.olsCheckFunction))
dialog$setRunFunction(toJava(.olsRunFunction))

# For debugging, comment out the following line. Use dialog$run() instead.
### return(dialog)
dialog$run()

}

# simulate data
x1 <- rnorm(100)
x2 <- rnorm(100)
y <- 4 + 2*x1 - .4*x2 + rnorm(100,sd = .2)
df <- data.frame(cbind(y,x1,x2))

# debug the run-function or the dialog
### runfunc <- TRUE
runfunc <- FALSE
if(runfunc == TRUE) {
.olsRunFunction(list(
'data'="df",
'dep'=c("y"),
'indep'=c("x1","x2")
))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vincent  
View profile  
 More options Nov 13 2012, 5:11 pm
From: Vincent <vincent.n...@gmail.com>
Date: Tue, 13 Nov 2012 14:11:43 -0800 (PST)
Local: Tues, Nov 13 2012 5:11 pm
Subject: Re: how best to debug dialog and run code

I guess the title of my post might be a bit misleading. I am not suggesting
my way 'is' the best way to debug your deducer code :) I should have added
a '?', i.e., 'how best to debug dialog and run code?'


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Fellows  
View profile  
 More options Nov 18 2012, 3:57 pm
From: Ian Fellows <ifell...@gmail.com>
Date: Sun, 18 Nov 2012 12:57:27 -0800
Local: Sun, Nov 18 2012 3:57 pm
Subject: Re: how best to debug dialog and run code
That is pretty much correct. It should be said that programming in
general has a large component of
bang-head-on-table-why-won't-this-work to it, especially when you are
starting out. One thing that is useful is to print out things with the
cat function.

Debugging dialogs in R is actually quite a bit easier than in Java, as
there is no need to recompile or reinstall a package.

best,
Ian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »