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
bobmorrane
Level V

How To send a data table as an argument into a function

Hello everyone,

 

 

 

So I have been trying to do this for a while now and I can't get my head around it.

 

I'm making a script to export multiple picture from a few different folders. I have created an "import" function and a "trim" function.

Import = Function ({path}, 

dtimport= Multiple File Import (
// the import arguments
)<< Import Data;
Return (dtimport);
};
Trimtables  = Function ({table, arg1, arg2, arg3},

table:Image<<Set Name ("Image" || Char(arg1)) ;
// anda Bunch of other instruction
};

path = Pick Directory();

dt1=Import (path);

So it works fine until I try to send this table as argument for my trim function.

 

I understand that dt1 is not my actual table but just a pointer and that If i send that directly to the table the function would only have a pointer to that pointer. So I tried using :

 

 

dt1<<Set Name ("My data table");


Trimtables (Data Table ("my data table"), arg1, arg2 ,arg3);

and That works fine. The issue is when I try not to use a custom title for each table. I tried the following :

 

 

Trimtables (dt1<<Get Name(), arg2, arg3, arg4);

But this does not work. I tried a whole lot of variations (while changing what the function expects):

Trimtable (Char(dt1<<Get Name ()), arg1, arg2, arg3);

or

Trimtable (Eval(dt1), arg1, arg2, arg3);

or

Trimtable (Print(Char(dt1<<Get Name ()), arg1, arg2, arg3);

But nothing seems to work . Essentially what I would need would be like in C where you would send &datatable as argument. I'm sure this is pretty trivial but for the lfie of me I can't get my head around it.

 

Any ideas ?

Thanks,

Bob

~~Bob~~
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: How To send a data table as an argument into a function

MFI returns a list of the tables it opened, even if there is only one table. The result of your import function is probably a list with a single item, { datatable("pictures.jmp") } or similar. You probably need something like

TrimTable( dt1[ 1 ] )

to get the first data table from the list.

Craige

View solution in original post

5 REPLIES 5
bobmorrane
Level V

Re: How To send a data table as an argument into a function

and of course I tried this :

 

Trimtables (Data Table (dt1<<Get Name()), arg1, arg2 ,arg3);

 I guess the Get Name() instruction just does not return a normal string but a weird thing like "!\ "data table name" !\"

I guess in last resort I could trim that string to remove the special characters but that sounds like a desperate measure

~~Bob~~
pmroz
Super User

Re: How To send a data table as an argument into a function

Try putting some show statements inside your functions to see what's going on.  This code snippet works OK:

fn1 = function({tbl_path},
	dt_fn1 = open(tbl_path);
	dt_fn1;
);

fn2 = function({tbl, arg1, arg2},
	show(tbl, arg1, arg2);
	tbl:height << set name("New Name");
);

dt = fn1("$sample_data\Big Class.jmp");
show(dt);
fn2(dt, "Hello", "World");
Craige_Hales
Super User

Re: How To send a data table as an argument into a function

MFI returns a list of the tables it opened, even if there is only one table. The result of your import function is probably a list with a single item, { datatable("pictures.jmp") } or similar. You probably need something like

TrimTable( dt1[ 1 ] )

to get the first data table from the list.

Craige
bobmorrane
Level V

Re: How To send a data table as an argument into a function

Thanks Craige_Hales,


I was writing my reply when you posted yours. Good thing we came to the same conclusion



~~Bob~~
bobmorrane
Level V

Re: How To send a data table as an argument into a function

Hi pmroz,

Thanks for the quick reply.

I have been using the Caption function, which I guess is pretty similar to Show, with the added benefit that it display over everything else instead of writing in the log which gets pretty messy as soon as there are errors.

 

 

I have made the following code, which works :

 

Names Default To Here( 1 );
Mydt = Function({},
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt<<Set Name ("Mydt");
m=dt<<Get Name ();
//Print (m); Wait (3);


Return (m);
);

mytrim = Function ({ref},
 
dttrim = Data Table (Char(ref));
dttrim<<Delete Columns (:Weight);

);

dtref=Mydt();

dt1 = Data Table (dtref);
mytrim (dtref);

dt1<< Set Name ("new name");

So this tells me it is indeed possible to use the data table name as a reference and work from there.

The issue is, when I try to use this code with a table created with the Multiple File Import function, then it doesn't work any more, which tells me something else is afoot.

 

I think when creating a table from multiple import, jmp considers the object not as a data table but as something else. When I use the get name function, it returns not a normal quoted string but a list.

 

It seems to be working now that I use the following in the "mydt" function :

 

m = dt[1] <<Get Name ();

Still this feels a bit weird. Any ideas why importing multiple files leads to this behaviour ?

 

 

~~Bob~~