cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
0 Kudos

data table : message column exists(colname)?

☐ cool new feature
☑ could help many users!

☑ removes a „bug“

☐ nice to have

☐ nobody needs it

 

Is there a column colname in my data table?
This is one of the questions which are asked most often in the community:

https://community.jmp.com/t5/Discussions/Check-column-name-if-existing/m-p/312011/highlight/true#M56...

https://community.jmp.com/t5/Discussions/How-to-check-if-list-of-columns-exist-and-report-those-that...

https://community.jmp.com/t5/Discussions/If-column-exists/td-p/348

https://community.jmp.com/t5/Discussions/how-to-creat-new-column-if-same-name-column-does-not-exist/...

https://community.jmp.com/t5/Discussions/Create-a-new-Row-column-only-if-it-does-not-exist/td-p/3091...

https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6268#M6267

https://community.jmp.com/t5/Discussions/Validate-column-name-exists-before-graphing/m-p/5088#M5087

 

So, it seems that it's not straightforward enough, how it is implemented at the moment.

 

But it is even more interesting - and bears a lot of dangers.
A user who doesn't know about the stumbling blocks associated with JSL naming conventions, most probably just writes

Contains( dt << Get Column Names(String), "age" )

into his code. Quite easy ...
but extremely dangerous - see:

https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572468

What looks like strange discussions of some jsl scripting nerds shows that the above statement, sure, will work for many cases, but:
will fail once spaces, capital letters, special character are in the column names.

 

To prevent users from using such dangerous code, it's the best to "instutionalize"

- i.e. provide the users an easy solution which accounts automatically for all pitfalls.

 

My wish:
it should be possible to ask a data table:

 

dt << contains column("colname")

 

 

This function can account for all pitfalls:

- compare with exact match - or check match for as name("colname"), accounting for spaces

- distinguish or don't distinguish lower/capital letters

- handle special characters

 

The benefit:

- less questions in the community

- automatically better code.

- less frustration.

 

more wishes submitted by  hogi_2-1702196401638.png

7 Comments
jthi
Super User

It could be better to make JMP understand that those are either same or different column names? This could of course break things, so might not be so easy to implement.

 

Something is a bit confusing here:

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt:age << set name("a g e");
dt:age[1] = 999;


Show(Column(dt, "age")); //Column(dt, "age") = Column("a g e");
Show(dt:age[1]); //dt:age[1] = 999;

dt << New Column("age", Numeric, Ordinal);
Show(Column Name(2) == Column Name(6)); // Column Name(2) == Column Name(6) = 1; // Columns don't need unique names?
Show(Column(dt, "age")); //Column(dt, "age") = Column("age");
dt:age[1] = 9999;
Show(dt:age[1]); //dt:age[1] = 9999;

wait(1);

dt << Delete Column("age");
Show(Column(dt, "age")); //Column(dt, "age") = Column("a g e");
Show(dt:age[1]); //dt:age[1] = 999;

Do columns follow some specific naming? Do follow names are required to start with alphabetic characters or underscore, but whitespaces do matter (sometimes) for columns. Maybe the issue (if there is one) is just how column referencing works?

Status changed to: Acknowledged

Hi @hogi, thank you for your suggestion! We have captured your request and will take it under consideration.

mia_stephens
Staff

Thank you @hogi, and @jthi for commenting. Changing the status to investigating.

mia_stephens
Staff
Status changed to: Investigating
 
mia_stephens
Staff
Status changed to: Yes, Stay Tuned!

Development is exploring a solution: "to have a message on the table to ask directly, like dt << Has Column("age") , potentially with an option to give different answers if you want Exact matches or Name (space and case insensitive) matches".

 

Changing to Yes, Stay Tuned.

hogi
Level XI

Thanks

Status changed to: Delivered

This is in JMP 18.