BookmarkSubscribe
Choose Language Hide Translation Bar
msharp
Super User

JSL - How to get the type of Analysis

Is there an easy way to tell what type of analysis I'm looking at from a JSL perspective?  I want to know if the outline box is a Oneway, Bivariate, ect.  I thought there was an easy way to do this, like analysis << Class Name (but that didn't work - just returns OutlineBox). 

 

I would like to run different code based on the type of analysis in any given window.  This is assuming I don't explicitly create the analysis and know what it is.  The only way I could think of is with the below code, but it feels incredibly glassy to me.  Is this the only way?

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
analysis = dt << Fit Y by X(
	Y( :weight ),
	X( :height, :sex )
);
for(i=1, i<=nitems(analysis), i++,
	if(contains(Log Capture(print(analysis[i])), "Oneway"),
		Print("It's a Oneway"),
		Print("It's not Oneway")
	);
);

@Craige_Hales@ms@Jeff_Perkinson

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User ms
Super User

Re: JSL - How to get the type of Analysis

Sorry, I was too quick to answer and did not really understand the question. 

 

In the loop in your example Char(analysis[i]) would yield the same result as 

Log Capture(Print(analysis[i])).

 

Also xpath() could be worth exploring for more complex scenarios. For example, this code example returns a list of strings from the current report.

Current report()<< xpath("//OutlineBox[contains(@helpKey, 'Report')]/@helpKey");
7 REPLIES 7
ms
Super User ms
Super User

Re: JSL - How to get the type of Analysis

 

analysis << get scriptable object;

Returns a list of the analyses

msharp
Super User

Re: JSL - How to get the type of Analysis

This appears to just be returning the analysis object:

scriptObjs = analysis << get scriptable object;
print(scriptObjs);
print(analysis);
print(scriptObjs == analysis); //returns true

I'm still left with my log capture() method to scrape the scriptsObjs.

0 Kudos
pmroz
Super User

Re: JSL - How to get the type of Analysis

How about converting the analysis list to char and then parsing the result?

ca = char(analysis);
analysis_list = words(ca, "{}[], ");
{"Bivariate", "Oneway"}
msharp
Super User

Re: JSL - How to get the type of Analysis

Thanks!  The obvious solution sometimes can escape you, I'm not sure where my mind was.  I still wish the box object contained a name or type parameter.

0 Kudos
pmroz
Super User

Re: JSL - How to get the type of Analysis

Glad it helped.  I've been using the char() function to convert things to text to write to Oracle, to save a dialog box state.  In particular I've used it for lists.  Note that doing things in reverse requires a parse.

a = {"xyz", "Hello", "World"};
b = char(a);
"{\!"xyz\!", \!"Hello\!", \!"World\!"}"

c = parse(b);
{"xyz", "Hello", "World"}

 

0 Kudos
ms
Super User ms
Super User

Re: JSL - How to get the type of Analysis

Sorry, I was too quick to answer and did not really understand the question. 

 

In the loop in your example Char(analysis[i]) would yield the same result as 

Log Capture(Print(analysis[i])).

 

Also xpath() could be worth exploring for more complex scenarios. For example, this code example returns a list of strings from the current report.

Current report()<< xpath("//OutlineBox[contains(@helpKey, 'Report')]/@helpKey");
msharp
Super User

Re: JSL - How to get the type of Analysis

thanks @pmroz, yeah I often use the char() function similar to you, again, not sure why I didn't think of it in the moment.

 

The XPATH function appears super useful.  The syntax doesn't appear too complicated and there's tutorials on W3schools, so that's a plus. https://www.w3schools.com/xml/xpath_intro.asp

 

Using XPATH I can just select the reports of the type I want.  Super useful!  Going to have to dig into this a bit.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
analysis = dt << Fit Y by X(
	Y( :weight ),
	X( :height, :sex )
);

OnewayReports = Current report()<< xpath("//OutlineBox[contains(@helpKey, 'Oneway Report')]/.");
oneway = OnewayReports[1];
oneway << Set Title("Test");
0 Kudos