<?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 include specific functions instead of whole script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287945#M55516</link>
    <description>&lt;P&gt;Sorry my mistake, a name expr( function is needed when copying the function.&amp;nbsp; Here is a revised example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;included.jsl:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;f = function({x,y}, x + y);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Script to load function:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

//load the new file in a local here namespace
Eval( Eval Expr( local here(
	include("included.jsl");
	
	//Reference the original script's here namespace in this new here namespace
	//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
	//outside of this 'local here' context.
	//from the other.
	ns = Expr( namespace("here") );
	
	//copy and functions you want to keep
	ns:f = Name expr( here:f );
) ) );

//Now functions are in here namespace
f(1,2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Aug 2020 11:30:45 GMT</pubDate>
    <dc:creator>ih</dc:creator>
    <dc:date>2020-08-25T11:30:45Z</dc:date>
    <item>
      <title>How to include specific functions instead of whole script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287341#M55468</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to import only specific functions from a JSL file?&lt;/P&gt;&lt;P&gt;For example in python you can write: "from pandas import read_csv" to import only the read_csv function. Currently in JMP I always import a whole JSL file with many functions defined in it, and I think it would be better to import just the functions I need for the sake of clarity (and maybe performance).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:35:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287341#M55468</guid>
      <dc:creator>rcookie</dc:creator>
      <dc:date>2023-06-09T23:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to include specific functions instead of whole script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287352#M55469</link>
      <description>I am not aware of any way to include only a subset from an include file.</description>
      <pubDate>Mon, 24 Aug 2020 08:11:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287352#M55469</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-08-24T08:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to include specific functions instead of whole script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287404#M55476</link>
      <description>&lt;P&gt;I don't know of anything as straight forward as python offers either, but here are two options that get the job done:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider a file called included.jsl:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;a = function({}, 1);
b = function({}, 2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To load the function directly in the context of your script:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

//load the new file in a local here namespace
Eval( Eval Expr( local here(
	include("included.jsl");
	
	//Reference the original script's here namespace in this local here namespace
	//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
	//outside of this 'local here' context.
	ns = Expr( namespace("here") );
	
	//copy and functions you want to keep
	ns:a = here:a;
) ) );

//Now functions are in this namespace
a();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or, to keep the function in a separate namespace:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

//create namespace to hold functions you want to keep from included file
ns = new namespace();

//load the new file in a local here namespace
Eval( Eval Expr( local here(
	include("included.jsl");
	
	//Reference the ns namespace in this new here namespace
	ns = Expr( ns );
	
	//pick and choose any functions you want to keep
	ns:a = here:a
	
) ) );

//Now either call the functions from the ns namespace
ns:a();

//or copy them to the here namespace
a = ns:a;
a();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 17:37:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287404#M55476</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2020-08-24T17:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to include specific functions instead of whole script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287943#M55514</link>
      <description>&lt;P&gt;Thanks for your help, this definitely works for functions without any argument.&lt;/P&gt;&lt;P&gt;Unfortunately I run into an error when trying to import a function with two arguments, the error states I don't give any argument when the function requires 2 of them (which is true). Here is the sample code:&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);
MyRejet = 1;
Lot_nom = "G123456";

//load the new file in a local here namespace
Eval( Eval Expr( local here(
	Include("include.jsl");;
	
	//Reference the original script's here namespace in this local here namespace
	//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
	//outside of this 'local here' context.
	ns = Expr( namespace("here") );
	
	print(ns);
	
	//copy and functions you want to keep
	ns:DataExtraction = here:DataExtraction;
) ) );

//Now functions are in this namespace

DataExtraction(Lot_nom, MyRejet);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Do you know where the error is? I tried specifying arguments&amp;nbsp; when copying the functions but it does not seem to solve the issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 08:46:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287943#M55514</guid>
      <dc:creator>rcookie</dc:creator>
      <dc:date>2020-08-25T08:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to include specific functions instead of whole script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287945#M55516</link>
      <description>&lt;P&gt;Sorry my mistake, a name expr( function is needed when copying the function.&amp;nbsp; Here is a revised example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;included.jsl:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;f = function({x,y}, x + y);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Script to load function:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

//load the new file in a local here namespace
Eval( Eval Expr( local here(
	include("included.jsl");
	
	//Reference the original script's here namespace in this new here namespace
	//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
	//outside of this 'local here' context.
	//from the other.
	ns = Expr( namespace("here") );
	
	//copy and functions you want to keep
	ns:f = Name expr( here:f );
) ) );

//Now functions are in here namespace
f(1,2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 11:30:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287945#M55516</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2020-08-25T11:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to include specific functions instead of whole script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287992#M55528</link>
      <description>Indeed it works, thanks a lot!</description>
      <pubDate>Tue, 25 Aug 2020 15:25:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-include-specific-functions-instead-of-whole-script/m-p/287992#M55528</guid>
      <dc:creator>rcookie</dc:creator>
      <dc:date>2020-08-25T15:25:52Z</dc:date>
    </item>
  </channel>
</rss>

