- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How do I pass in a variable number of variables to a function as an array?
I am hoping to make some functions I have a little more reusable as an example, I am creating a summary table with specific columns from my data set. I would like to pass in the columns list as an argument to allow me to have one "GetSummary" function rather than a "GetExperimentsSummary" and "GetCompoundsSummary" , but as these need different numbers of columns I need to be able to package the list of columns separately (most likely in my class definition) and then pass them to the function as one argument. Is this possible in jsl? What would the syntax be? Examples of my get experiments and get compounds below, and I am on JMP18.
//Get Experiments function
getexperimentssummary = function ({},
original_data << Summary(
Group(
:ExperimentID, :Read Date, :Experiment Type, :Plate Size, :Plate Type,
:Dispense Mode, :Probook Number, :Probook Page Number, :Experiment Notes
),
Freq( "None" ),
Weight( "None" ),
output table name("Experiment_summary")
);
experiment_summary = Data Table ("Experiment_summary");
experiment_id = "ExperimentID";
);
//Get Compounds Summary
getcompoundssummary = Function( {},
original_data << Summary(
Group(
:CompoundID, :Compound, :Compound Lot Number, :Compound Supplier, :Compound Catalog Number
),
Freq( "None" ),
Weight( "None" ),
output table name("Compound_summary")
);
compound_summary = Data Table ("Compound_summary");
Compound_ID = "CompoundID";
);
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I pass in a variable number of variables to a function as an array?
Are you looking for something like this?
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
get_summary = function({dt, collist}, {Default Local},
dt_summary = dt << Summary(
Group(Eval(collist)),
Freq("None"),
Weight("None"),
Link to original data table(0),
output table name((dt << get name) ||" Summary")
);
return(dt_summary);
);
dt_summary1 = get_summary(dt, {"sex"});
dt_summary2 = get_summary(dt, {"sex", "age"});
-Jarmo