<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How To send a data table as an argument into a function in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241119#M47614</link>
    <description>&lt;P&gt;Try putting some show statements inside your functions to see what's going on.&amp;nbsp; This code snippet works OK:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;fn1 = function({tbl_path},
	dt_fn1 = open(tbl_path);
	dt_fn1;
);

fn2 = function({tbl, arg1, arg2},
	show(tbl, arg1, arg2);
	tbl:height &amp;lt;&amp;lt; set name("New Name");
);

dt = fn1("$sample_data\Big Class.jmp");
show(dt);
fn2(dt, "Hello", "World");
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Jan 2020 14:36:16 GMT</pubDate>
    <dc:creator>pmroz</dc:creator>
    <dc:date>2020-01-14T14:36:16Z</dc:date>
    <item>
      <title>How To send a data table as an argument into a function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241096#M47611</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have been trying to do this for a while now and I can't get my head around it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm making a script to export multiple picture&amp;nbsp;from a few different folders. I have created an "import" function and a "trim" function.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Import = Function ({path}, 

dtimport= Multiple File Import (
// the import arguments
)&amp;lt;&amp;lt; Import Data;
Return (dtimport);
};
Trimtables  = Function ({table, arg1, arg2, arg3},

table:Image&amp;lt;&amp;lt;Set Name ("Image" || Char(arg1)) ;
// anda Bunch of other instruction
};

path = Pick Directory();

dt1=Import (path);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So it works fine until I try to send this table as argument for my trim function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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&amp;nbsp;that pointer. So I tried using&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1&amp;lt;&amp;lt;Set Name ("My data table");


Trimtables (Data Table ("my data table"), arg1, arg2 ,arg3);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and That works fine. The issue is when I try not to use a custom title for each table. I tried the following :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Trimtables (dt1&amp;lt;&amp;lt;Get Name(), arg2, arg3, arg4);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But this does not work. I tried a whole lot of variations (while changing what the function expects):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Trimtable (Char(dt1&amp;lt;&amp;lt;Get Name ()), arg1, arg2, arg3);

or

Trimtable (Eval(dt1), arg1, arg2, arg3);

or

Trimtable (Print(Char(dt1&amp;lt;&amp;lt;Get Name ()), arg1, arg2, arg3);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But nothing seems to work&amp;nbsp;. Essentially what I would need would be like in C where you would send &amp;amp;datatable as argument. I'm sure this is pretty trivial but for the lfie of me I can't get my head around it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas ?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Bob&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 13:24:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241096#M47611</guid>
      <dc:creator>bobmorrane</dc:creator>
      <dc:date>2020-01-14T13:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: How To send a data table as an argument into a function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241102#M47612</link>
      <description>&lt;P&gt;and of course I&amp;nbsp;tried this&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Trimtables (Data Table (dt1&amp;lt;&amp;lt;Get Name()), arg1, arg2 ,arg3);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I guess the Get Name() instruction just does not return a normal string but a weird thing like "!\ "data table name" !\"&lt;/P&gt;&lt;P&gt;I guess in last resort I could trim that string to remove the special characters but that sounds like a desperate measure&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 13:29:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241102#M47612</guid>
      <dc:creator>bobmorrane</dc:creator>
      <dc:date>2020-01-14T13:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: How To send a data table as an argument into a function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241119#M47614</link>
      <description>&lt;P&gt;Try putting some show statements inside your functions to see what's going on.&amp;nbsp; This code snippet works OK:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;fn1 = function({tbl_path},
	dt_fn1 = open(tbl_path);
	dt_fn1;
);

fn2 = function({tbl, arg1, arg2},
	show(tbl, arg1, arg2);
	tbl:height &amp;lt;&amp;lt; set name("New Name");
);

dt = fn1("$sample_data\Big Class.jmp");
show(dt);
fn2(dt, "Hello", "World");
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 14:36:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241119#M47614</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-01-14T14:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: How To send a data table as an argument into a function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241136#M47619</link>
      <description>&lt;P&gt;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, &lt;STRONG&gt;{&lt;/STRONG&gt; datatable("pictures.jmp")&lt;STRONG&gt; }&lt;/STRONG&gt; or similar. You probably need something like&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;TrimTable( dt1[ 1 ] )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to get the first data table from the list.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 15:10:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241136#M47619</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-01-14T15:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: How To send a data table as an argument into a function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241139#M47622</link>
      <description>&lt;P&gt;Hi pmroz,&lt;/P&gt;&lt;P&gt;Thanks for the quick reply.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made the following code, which works :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Mydt = Function({},
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt&amp;lt;&amp;lt;Set Name ("Mydt");
m=dt&amp;lt;&amp;lt;Get Name ();
//Print (m); Wait (3);


Return (m);
);

mytrim = Function ({ref},
 
dttrim = Data Table (Char(ref));
dttrim&amp;lt;&amp;lt;Delete Columns (:Weight);

);

dtref=Mydt();

dt1 = Data Table (dtref);
mytrim (dtref);

dt1&amp;lt;&amp;lt; Set Name ("new name");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So this tells me it is indeed possible to use the data table name as a reference and work from there.&lt;/P&gt;&lt;P&gt;The issue is, when I try to use this code&amp;nbsp;with&amp;nbsp;a table created with the Multiple File Import function, then&amp;nbsp;it doesn't work any more, which tells me something else is afoot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think when creating a table from multiple import, jmp considers the object not as&amp;nbsp;a data table but as something else. When I use the get name function, it returns not a normal quoted string but a list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to be working now that I use the following in the "mydt" function&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;m = dt[1] &amp;lt;&amp;lt;Get Name ();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Still this feels a bit weird. Any ideas why importing multiple files&amp;nbsp;leads to&amp;nbsp;this behaviour ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 15:24:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241139#M47622</guid>
      <dc:creator>bobmorrane</dc:creator>
      <dc:date>2020-01-14T15:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How To send a data table as an argument into a function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241141#M47624</link>
      <description>Thanks Craige_Hales,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I was writing my reply when you posted yours. Good thing we came to the same conclusion :)&lt;/img&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Jan 2020 16:06:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-send-a-data-table-as-an-argument-into-a-function/m-p/241141#M47624</guid>
      <dc:creator>bobmorrane</dc:creator>
      <dc:date>2020-01-14T16:06:03Z</dc:date>
    </item>
  </channel>
</rss>

