boolean expressions involving sliders in manipulate
The following seems rather odd, and it is causing problems with a routine I have written using the manipuate fucntion, in which a slider is passed to a function whose action depends on the the resuklt of a boolean evaluation of the slider. Unfortunately it seems that expressions of the form
slider == a.particular.number
always evalaute to false, no matter what the value of the slider is.
For example, in this code:
manipulate(
a=slider(-3,3,step=0.1,initial=1), {plot(1~1) a==0} )
you find that the response to the console is always FALSE, even when you set the a-slider to 0.
Is there a workaround? I'd like the expression to evaluate as TRUE when the slider does equal the specified value.
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Josh Paulson on 19 Aug, 2012 12:25 PM
Homer,
This becomes more apparent when you use the following function:
Notice that as you place the slider on "0", it will print the value as something very close to zero such as "1.665335e-16". This is just how R works and you'll need to use a different comparison operator. For example, the following takes this into account:
For more information, take a look at the docs for functions such as:
Josh
3 Posted by hwhite0 on 20 Aug, 2012 12:48 PM
Thanks, Josh,
as the condition in an if statement did exactly what I needed.
Regards,
Homer
Support Staff 4 Posted by Josh Paulson on 20 Aug, 2012 12:55 PM
Homer,
Glad to help and all the best!
Josh
Josh Paulson closed this discussion on 20 Aug, 2012 12:55 PM.