cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
lodey101
Level II

Check to see if a list is empty

Hi there,

     This may be an easy question to answer but what I am trying to do is use JMP  to count the number of files contained within a specific directory and return a value of either 0 if none exist or the number of files.

I know that using the Files In Directory function will list the files contained as a list but what I want to do is convert this to a numerical value:

ie:


//set up raw dir


raw_dir = "C:\\My PhotoFilmStrips\";


_files = Files In Directory( raw_dir );



//show files


show(_files);



show( Type(_files), Is Empty(_files), Is Missing(_files), _files==Empty());


If I run the above script i get the following with a file contained within the raw directory:

Type(_files) = "List";

Is Empty(_files) = 0;

Is Missing(_files) = {0};

_files == Empty() = 0;

When the directory is empty I get:

Type(_files) = "Number";

Is Empty(_files) = 0;

Is Missing(_files) = 1;

_files == Empty() = .;

How can I make use of the Is Missing variable - ie if it is 1 then assign the number to a variable like tt=0 and when it the Is Missing variable is 0 then tt=1

Any help would be appreciated

Rgds

Colin

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Check to see if a list is empty

In JMP 10 and 11 an empty directory gives an empty list, not a missing value and I would thus expect Is Missing() to return 0. Strangely, If applied to an empty list Is Missing() returns an empty list, not 0 or 1 that is the expected output from a boolean function. I am not sure how it works in JMP 9.


I suggest you use N Items() instead. For example:

tt=(nitems(_files)>0);

If using Is Missing() you can switch between 0 and 1 with the NOT operator, i.e. !Is Missing()

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Check to see if a list is empty

In JMP 10 and 11 an empty directory gives an empty list, not a missing value and I would thus expect Is Missing() to return 0. Strangely, If applied to an empty list Is Missing() returns an empty list, not 0 or 1 that is the expected output from a boolean function. I am not sure how it works in JMP 9.


I suggest you use N Items() instead. For example:

tt=(nitems(_files)>0);

If using Is Missing() you can switch between 0 and 1 with the NOT operator, i.e. !Is Missing()

Re: Check to see if a list is empty

Is Missing() on an empty list will return an empty list, because it is operating on each element of a list.  If the list is empty, there are no elements for Is Missing() to operate on, so it returns the empty list.  However, a better way to see this is the following example:

lst = {1,2,.,""};

ismissing(lst);

Michael Crotty
Principal Statistical Writer
Manager, Statistical Documentation
JMP Development