# Using ifelse function in DS

**URL:** <https://datashield.discourse.group/t/using-ifelse-function-in-ds/261>\
**Category:** Beginner Support\
**Created:** [27 July 2020 10:02 UTC](https://datashield.discourse.group/t/using-ifelse-function-in-ds/261 "2020-07-27T10:02:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack.lyons](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jack.lyons](https://datashield.discourse.group/u/jack.lyons)\
**Post date:** [27 July 2020 10:02 UTC](https://datashield.discourse.group/t/using-ifelse-function-in-ds/261/1 "2020-07-27T10:02:12Z")

</div>

I’ve added `ifelse` to my list of assign methods on both my servers but when I try:

`ds.assign(toAssign = 'ifelse(D$VALUE<6, 1, 0), newobj = 'VAR1')`

I get a bad request error message. I’ll note that I’ve logged in via the R environment after the function was added to the list of assign methods and that `D$VALUE` is class `numeric`. Any ideas?

---

<div class="post-metadata">

**Author:** ![swheater](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/swheater/32/182_2.png) [@swheater](https://datashield.discourse.group/u/swheater)\
**Post date:** [27 July 2020 10:26 UTC](https://datashield.discourse.group/t/using-ifelse-function-in-ds/261/2 "2020-07-27T10:26:03Z")

</div>

Jack,

Could I confirm you have missed a ’ in your example, but not when you where testing. Which version of DataSHIELD are you using? I believe ‘\<’ isn’t permitted in strings.

Stuart

---

<div class="post-metadata">

**Author:** ![jack.lyons](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jack.lyons](https://datashield.discourse.group/u/jack.lyons)\
**Post date:** [27 July 2020 10:50 UTC](https://datashield.discourse.group/t/using-ifelse-function-in-ds/261/3 "2020-07-27T10:50:03Z")

</div>

> [@jack.lyons](#):
>
> ds.assign(toAssign = 'ifelse(D$VALUE\<6, 1, 0), newobj = ‘VAR1’)

Sorry, there is a typo there; it should be

`ds.assign(toAssign = 'ifelse(D$VALUE<6, 1, 0)', newobj = 'VAR1')`

If, as you say, boolean operators are not permitted in strings then I guess that explains the error. I’ll just have to think of an alternative solution.

Cheers, Jack

---

<div class="post-metadata">

**Author:** ![tombishop](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/tombishop/32/23_2.png) [@tombishop](https://datashield.discourse.group/u/tombishop)\
**Post date:** [27 July 2020 11:08 UTC](https://datashield.discourse.group/t/using-ifelse-function-in-ds/261/4 "2020-07-27T11:08:17Z")

</div>

Hi Jack,

I think the function you need is ds.Boole:

[https://cran.datashield.org/web/dsBaseClient/ds.Boole.html](https://cran.datashield.org/web/dsBaseClient/ds.Boole.html)

Tom

---

<div class="post-metadata">

**Author:** ![jack.lyons](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jack.lyons](https://datashield.discourse.group/u/jack.lyons)\
**Post date:** [27 July 2020 12:03 UTC](https://datashield.discourse.group/t/using-ifelse-function-in-ds/261/5 "2020-07-27T12:03:02Z")

</div>

Thanks Tom, that function provides what I was looking for.
