Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
ALopez
Level III

JSL error Not enough arguments in evaluation of 'Contains'

I have a list of "file names" and I want to create a sub-list of only those that their names contain/end in "_2020". I am using a Regex to select for those files: "_\d{4}".  However I am getting a "Not Enough Arguments" error.

If I test the ListIDs I get the expected list of file names, it is not empty. I will Appreciate any pointers on how to fix my script.

The log error is: not enough arguments in access or evaluation of 'Contains' , Contains/*###*/(Regex( Char( ListIDs[i] ), "_\d{4}" ))

Show (ListIDs);
ListIDs = {"2020-06","practice", "file1_2020", "file2_2020"}

SelectedIDs = {}; For (i = 1, i <= N Items (ListIDs), i++, If (Contains(Regex(Char(ListIDs[i]), "_\d{4}")), Insert Into (SelectedIDs, i); ); ); N Items (SelectedIDs); Print(SelectedIDs);
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ALopez
Level III

Re: JSL error Not enough arguments in evaluation of 'Contains'

Hi,

I decided to modify the script and use the function Regex Match.  This one got me closer to my goal.  This one returns the position on the list of the expected filenames.  How can I get the "Names" not their positions. 

ListIDs = {"2019-11", "2020-06", "file1_2020", "file2_2020"};

SelectedIDs = {};
For (i = 1, i <= N Items (ListIDs), i++,
If ((Regex Match (Char(ListIDs[i]), "_\d{4}") !={}),
	Insert Into (SelectedIDs, i);
	);
);
N Items (SelectedIDs);
Print(SelectedIDs);

View solution in original post

6 REPLIES 6
Highlighted

Re: JSL error Not enough arguments in evaluation of 'Contains'

You need the second argument for Contains() function to designate the target string. Like this:

 

Show (ListIDs);ListIDs = {"2020-06","practice", "file1_2020", "file2_2020"}SelectedIDs = {};
For (i = 1, i <= N Items (ListIDs), i++,
If (Contains(Regex(Char(ListIDs[i]), "_\d{4}"), "2020"),
	Insert Into (SelectedIDs, i);
	);
);
N Items (SelectedIDs);
Print(SelectedIDs);
Learn it once, use it forever!
Highlighted
ALopez
Level III

Re: JSL error Not enough arguments in evaluation of 'Contains'

Hi Mark,
Is the second argument the "Delimiter"? I would have thought that it would be "," not "2020".  The goal of the Regex is to select only files that have "_2020" or in the future "_2021", "_2021" etc. Sorry if I am not explaining myself.

Highlighted

Re: JSL error Not enough arguments in evaluation of 'Contains'

I think that you can simplify the test. You do not need Contains() and its use is problematic when its first argument is a missing value. This modification uses the Regex() function result directly. (I reformatted the script to make its structure easier to see.)

 

ListIDs = { "2020-06", "practice", "file1_2020", "file2_2020" };
Show( ListIDs );

SelectedIDs = {};

For( i = 1, i <= N Items (ListIDs), i++,
	If(
		Not( Is Missing( Regex( ListIDs[i], "_\d{4}" ) ) ),
			Insert Into( SelectedIDs, i );
	);
);
Print( SelectedIDs );
Learn it once, use it forever!
Highlighted
ALopez
Level III

Re: JSL error Not enough arguments in evaluation of 'Contains'

Hi,

I decided to modify the script and use the function Regex Match.  This one got me closer to my goal.  This one returns the position on the list of the expected filenames.  How can I get the "Names" not their positions. 

ListIDs = {"2019-11", "2020-06", "file1_2020", "file2_2020"};

SelectedIDs = {};
For (i = 1, i <= N Items (ListIDs), i++,
If ((Regex Match (Char(ListIDs[i]), "_\d{4}") !={}),
	Insert Into (SelectedIDs, i);
	);
);
N Items (SelectedIDs);
Print(SelectedIDs);

View solution in original post

Highlighted

Re: JSL error Not enough arguments in evaluation of 'Contains'

ListIDs[SelectedIDs];
Learn it once, use it forever!
Highlighted
ALopez
Level III

Re: JSL error Not enough arguments in evaluation of 'Contains'

Hi Mark, 

Thank you very much, I love your solution.  I am always amazed when the solution is some negative expression. 
like "Not( Is Missing( Regex( ListIDs[i], "_\d{4}" ) )". 

Article Labels