cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
hogi
Level XII

Custom function with varying number of input columns?

Hi,

 

is it possible to define a custom function which works for 2-5 selected columns?

Add Custom Functions(
	New Custom Function(
		"custom",
		"concat",
		Function( {col1, col2, col3=., col4=., col5=.},
			If(not (is missing(col 4)),
			Char(col1) || "_" || Char(col2)|| "_" || Char(col3)|| "_" || Char(col4)|| "_" || Char(col5),
			not (is missing(col 4)),
			Char(col1) || "_" || Char(col2)|| "_" || Char(col3)|| "_" || Char(col4),
			not (is missing(col 3)),
			Char(col1) || "_" || Char(col2)|| "_" || Char(col3),
			not (is missing(col 4)),
			Char(col1) || "_" || Char(col2))
		),
		<<Transform Category( 1 ),
		<<Description( "combine 2-5 columns with underscore" ),
		<<Example(
			Expr(
				Show( custom:concat( :height, :weight, :sex, :age, :name ) );
			)
		)
	)
);
4 REPLIES 4
pmroz
Super User

Re: Custom function with varying number of input columns?

How about passing the columns in as a list?  That way there's only one argument, and it can have as many columns as you want.

hogi
Level XII

Re: Custom function with varying number of input columns?

I suffer from the missing concatenate entry in the right click / new formula column menu.
I want to create my own function. 
I guess the custom function can just be used for transforms if the columns are listed individually.

Jeff_Perkinson
Community Manager Community Manager

Re: Custom function with varying number of input columns?

Concatenate is there in JMP 18. 

2024-12-04_11-05-55.109.png

 

-Jeff
hogi
Level XII

Re: Custom function with varying number of input columns?

Unfortunately, NOT in general.

 

Yes, there is such a function.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Formula Column(
	Operation( Category( "Character" ), "Concatenate with Underscore" ),
	Columns( :height, :weight )
);


It appears in the right-click new formula column menu if at least one of the columns is a character column.

Unfortunately, the setting disappears if all columns are numeric  : (

Until now, we used a special shortcut icon in a toolbar.
A few days ago, one of my colleagues asked why there is no such possibility via the right-click new formula column.
So close - but for many cases: not accessible via the GUI.