Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Radio buttons not working with R_Tool

jbh1128d1
10 - Fireball

Hello, 

 

I'm trying to mimic the count_regression radio function for my own r_tool based GLM.  Below I have the code and a picture of the radio buttons.  I copied the text from the count_regression but for some reason, my code does not recognize this.  Any thoughts on what I'm doing wrong?

 

#get distribution from questions.

 

if (!is.XDF) {
if ('%Question.quasipoisson%' == "True")
the_family <- "quasipoisson(link='log')"
if ('%Question.gamma%' == "True")
the_family <- "gamma(link='log')"
if ('%Question.tweedie%' == "True")
the_family <- "tweedie(var.power=1.5,link.power=0)"
} else {
the_family <- "quasipoisson(link='log')"


# Run the model

 

piecewise2 <- glm(the_form, control = glm_control, weights = eufactor, family = the_family, data = the_data3)

 

  distribution.JPG

3 REPLIES 3
JeffF
Alteryx
Alteryx

Hi @jbh1128d1

 

When you copied the radio button, did you change the name of the radio button back to "quasipoisson" in the annotations menu? When you copy and paste a radio button it is renamed to Radio Button (tool id).

 

RadiobuttonName.png

 

If named correctly, you should see the Question in the Workflow Constants:

QuestionConstant.png

 

 

jbh1128d1
10 - Fireball

Hey @JeffF.  This was also taken care by @DrDan.  See his reply below:  (If @DrDan would like to re-post that answer to this, I'll mark it as a solution).  

 

@jbh1128d1,

 

When you are working with a GUI elements, you get to write a lot of R code that works by parsing and evaluating strings. The problem in this particular case is in dealing with the family argument to glm, which wants to be passed family function object, and you are providing it with a character vector object ("the_family") instead. This is how you solve the problem:

 

piecewise2 <- eval(parse(text = paste0("glm(the_form, control = glm_control, weights = eufactor, family = ", the_family, ", data = the_data3)")))

 In this case, within the text string, what is in put in is not "the_family", but your actual argument (say quasipoisson(link='log'), so the string becomes

 

"glm(the_form, control = glm_control, weights = eufactor, family = quasipoisson(link='log'), data = the_data3)

 When this string is parsed and evaluated, you will get the model you were hoping to get.

 

Dan

DrDan
Alteryx Alumni (Retired)

@jbh1128d1,

 

Rather than re-post my comment to you (since you've included it here already), let me provide a link to the original Knowledge Base article: Guide to Creating Your Own R-Based Macro - Create and Test a Basic Macro.

 

Labels