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
Christian
Level I

Concatenate Tables and close the input files

I am looking for a way to close the tables that are open and have served for input

 

For( f2 = 1, f2 < N Items( Tables ), f2++,
        ConcTable = Tables[f2] <<  /*###*/Concatenate(
            Tables[f2 + 1],
            Output Table Name( "Both" )
        ) /*###*/;
        Close( filelist[f2], No Save );
    );

 

The answer in the log is:

 

Send Expects Scriptable Object in access or evaluation of 'Send' , Tables[f2] <<  /*###*/Concatenate( Tables[f2 + 1], Output Table Name( "Both" ) ) /*###*/

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Concatenate Tables and close the input files

here is a simple method to concatenate the tables, and close those not needed

Names Default To Here( 1 );
Final_Table="Data_" || char(ntable);
// Concatenate the tables and delete them.  Add all of the tables to the first table
dt-data table(1);
For( i = 2, i <= N Table(), i++,
	dt << concatenate(data table(i), append to first table(1));
	close(data table(i), nosave);
);
// Rename the table to the desired name
dt << set name(Final_Table);
Jim

View solution in original post

7 REPLIES 7
txnelson
Super User

Re: Concatenate Tables and close the input files

Here is a piece of code that will work, and follows the logic of what you have specified.  However, I don't understand why you would want to do this.......so maybe the result will not be what you are imagining.  If not reply with what the end result is supposed to be.

Names Default To Here( 1 );

// Create sample tables
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << subset( selected rows( 0 ), selected columns( 0 ), by( :age ) );
Close( dt, nosave );

// Create your Tables list
Tables = {};
For( i = 1, i <= N Table(), i++,
	Insert Into( Tables, Data Table( i ) << get name )
);

// Run the concatinations
For( f2 = 1, f2 < N Items( Tables ), f2++,
	ConcTable = Data Table( Tables[f2] ) << Concatenate( Data Table( Tables[f2 + 1] ), Output Table Name( "Both" ) );
	Close( Data Table( Tables[f2] ), No Save );
);
Jim
Christian
Level I

Re: Concatenate Tables and close the input files

Jim, thanks for the answer. Let me expand a little further. Goal is to concatenate a list of data tables and to delete double rows. Any data tables that have contributed to the final concatenated table to be closed. The number of input data tables is variable. The selection of the datatbales to be concatenated is following the rule that the beginning strings are equal and the final name of the concatenated data table is the same string.

 

Here now the code for concatenation and double row deletion plus saving the final table.

 

If(N Items(filelist)>0,

for    (nu_t = 1, nu_t <= num_tables, nu_t++,                

FinalTable  = Munger(filelist[1],6,4);
Final_Table = "Data_"||FinalTable||".jmp";
//Show(FinalTable);
for    (f2 = 1, f2 < nitems(Tables), f2++,
    ConcTable = Tables[f2] << Concatenate(Tables[f2+1], Output Table Name( "Both" ) );
    Close( Tables[f2] , No Save );
    );
    // Delete Doube Rows
    ConcTable = Current Data Table();
    col_min = Parse( "Col Min( Row(), :Name(\!"" || Concat Items( ConcTable << get column names( string ), "\!"), :Name(\!"" ) || "\!"))" );
    duplicates = [];
    For Each Row( If( col_min != Row(), duplicates |/= Row() ) );
    ConcTable << delete rows( duplicates );

ConcTable << Save(Path_datatable_out||Final_Table);

//For(cc=1,cc <= nitems(Tables),cc++, Close(Tables[cc], No Save));
);
); // If Condition

 

I am looking forward for your reply.

 

Christian

 

txnelson
Super User

Re: Concatenate Tables and close the input files

Can you please supply a sample of you data tables, and an illustration of what would be considered duplicate rows?

Jim
Christian
Level I

Re: Concatenate Tables and close the input files

Jim,

 

If you look in the two attched table, they have the same number of columns and column names. The only thing that differentiate both is the number of rows. Column #1 is the time stamp and based on this duplicates will be removed.

 

The method as scripted works. I am looking for an efficent way of saving the final table and close the tables that have been the input for the final.

 

Best regards,

Christian

txnelson
Super User

Re: Concatenate Tables and close the input files

here is a simple method to concatenate the tables, and close those not needed

Names Default To Here( 1 );
Final_Table="Data_" || char(ntable);
// Concatenate the tables and delete them.  Add all of the tables to the first table
dt-data table(1);
For( i = 2, i <= N Table(), i++,
	dt << concatenate(data table(i), append to first table(1));
	close(data table(i), nosave);
);
// Rename the table to the desired name
dt << set name(Final_Table);
Jim
rc_hertzy
Level III

Re: Concatenate Tables and close the input files

Nice solution. First, a typo (equal sign not minus sign):  fourth line should be  

dt=data table(1);

Now, how can I keep one column for the source? If I merely add

Create source column

in the Concatenate statement, I get successive source columns, and none is what I want - listing all source files. 

Related: when I manually concatenated files and copied the Source script from the output file to a script window, it would not run, giving error of not finding the listed filenames. Here is the script ( File1.jmp is the selected open file):

dt = Current Data Table();

dt << Concatenate(

Data Table( "File2.jmp" ),

Data Table( "File3.jmp" ),

Output Table( "Combinedtest.jmp"),

Create source column

);

 Thanks. -Rick

 

 

rc_hertzy
Level III

Re: Concatenate Tables and close the input files


@rc_hertzy wrote:

Nice solution. First, a typo (equal sign not minus sign):  fourth line should be  

dt=data table(1);

Now, how can I keep one column for the source? If I merely add

Create source column

in the Concatenate statement, I get successive source columns, and none is what I want - listing all source files. 

Related: when I manually concatenated files and copied the Source script from the output file to a script window, it would not run, giving error of not finding the listed filenames. Here is the script ( File1.jmp is the selected open file):

dt = Current Data Table();

dt << Concatenate(

Data Table( "File2.jmp" ),

Data Table( "File3.jmp" ),

Output Table( "Combinedtest.jmp"),

Create source column

);

 Thanks. -Rick

 

 


I found my error in the last part. I had renamed one data file so of course the script could not find it. 

Still I would like a way to modify your solution to add a source column so I do not need to explicitly list all the open files. Thanks.