Dear OF Team,

Is there a way to do the following test more nicely/shorter: tree[species=1 or species=8 or species=10 or species=11 or species=12 or species=16 or species=19 or species=22 or species=23]

What I'm looking for is something like this (e.g. in R): tree[species %in% c(1,8,10,11,12,16,19,22,23)]

Could this be implemented if doesn't exist yet?

Thanks! Andras

asked 17 May '18, 11:42

Andras's gravatar image

Andras
18481952
accept rate: 0%


Hi András,
In the latest version of Collect (3.22.x) there is a new function idm:array that you could use in combination with idm:contains function to simplify your expression, that will become:

idm:contains(idm:array(1,8,10,11,12,16,19,22,23), species)

Many thanks,
Open Foris Team

permanent link

answered 07 Jun '18, 10:41

Stefano%20%28OF%29's gravatar image

Stefano (OF) ♦♦
4.7k19
accept rate: 20%

Hi,

It seems there is a problem with the expression above. If I try to use it to get a subset of a group of items, it doesn't work:

count(parent()/tree[idm:contains(idm:array(1,8,10,11,12,16,19,22,23),species)])

Am I doing something wrong?

(26 Jun '18, 10:26) Andras Andras's gravatar image

The species code is an alphanumeric value, so it must be wrapped into single or double quotes. Try to use this expression instead: count(parent()/tree[idm:contains(idm:array('1','8','10','11','12','16','19','22','23'),species)])
However, I would split the expression into 2 separate calculated attributes, one attribute that says if a species in of a specific type and the other one that counts the trees of that species, and I would even move the count outside of the 'tree' entity, since it does not depend on the current tree item.

(26 Jun '18, 14:28) Stefano (OF) ♦♦ Stefano%20%28OF%29's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×493

question asked: 17 May '18, 11:42

question was seen: 1,734 times

last updated: 26 Jun '18, 14:28