dthor
dthor

Reputation: 1877

JMP Scripting: Why doesn't my column data get sent into a Function?

I am creating a JSL script for some of my datatables and need my function to act on a column.

I can get the function to act on the column during a plotting event, but not with standard operations.

Here's an example that works. This acts on the current datatable and plots up the Distribution for :Column1, which happens to be Nominal Character with 4 unique items in it.

a = Function(
        {col},                 // Function parameters
        {Default Local},       // Local variables
        Distribution(
            Nominal Distribution(
                Column( col ),
                Horizontal Layout( 1 ),
                Vertical( 0 )
            );
        );
    );

dt = Current Data Table();
a(Expr(:Column1));

Note the Expr() around :Column1. Without this, the Distribution function does not work.


What I'm trying to do is the following, but it doesn't work. What it should do is show the number of unique items in :Column1.

a = Function(
        {col},                 // Function parameters
        {Default Local},       // Local variables
        retval = associative array(col);
        Show(nitems(retval));
    );

dt = Current Data Table();
a(Expr(:Column1));

    Returns in Log Window:
    N Items(retval) = 0;        // Should be 4

If I run the script without trying to wrap it in a function, then it works just fine:

retval = associative array(:Column1);
Show(nitems(retval));

    Returns in Log Window:
    N Items(retval) = 4;        // My column happens to have 4 unique entries in it.

I'm fairly certain that my issue has something to do with namespace inside the function, but I can't seem to figure it out. Does anyone have any suggestions?

Upvotes: 0

Views: 3792

Answers (1)

Faller
Faller

Reputation: 1698

It is (from what I've seen) just an issue with the scoping operator : in :Column1.

Try using

a = Function(
    {col},                 // Function parameters
    {Default Local},       // Local variables
    retval = associative array(col<<Get Values)<<Get Keys;
    Show(nitems(retval));
);

dt = Current Data Table();
a(column(dt, "Column1"));

it returned

N Items(retval) = 9; 

Upvotes: 1

Related Questions