Estoy escribiendo una función auxiliar que cambia el nombre de un grupo de columnas si contiene un nombre de columna específico.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
/*//Use if already existing
dt = Data Table ("Cities");
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
Esto funciona bien con columnas agrupadas básicas, pero falla si hay un grupo heredado de una referencia de enlace:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
dt_state = Open( "$SAMPLE_DATA/State Abbreviations.jmp" );
//Need more than 1 column
dt_state << New Column( "Dummy", Numeric, "Continuous", Format( "Best", 12 ));
//Link Tables
dt_state:Abbreviations << Set Property( "Link ID", 1 );
dt:State << Set Property("Link Reference", Reference Table(dt_state));
/*//Use if already existing
dt = Data Table ("Cities");
dt_state = Data Table( "State Abbreviations" );
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
Firstly, the << Get Name function errors on :Ozone, which worked fine in the simpler example.
Aunque se resuelva ese error, la columna vinculada se ve diferente en el registro:
column = :Y;
column = Referenced Column(<STRONG>"Estados de EE. UU."</STRONG>, Reference(Column(:State), Reference(Column(:U.S. States))));
¿Cómo se extrae el nombre del texto? Por ejemplo: "Estados de EE. UU. [Estado]"
Lo más probable es que estés teniendo problemas porque JMP está haciendo referencia a una tabla de datos incorrecta. Mi sugerencia es que SIEMPRE uses referencias de columna explícitas -> convierte siempre tus columnas (referencias) a cadenas y luego usa diferentes formatos según sea necesario. En tu caso, algo como esto
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Cities.jmp");
dt_state = Open("$SAMPLE_DATA/State Abbreviations.jmp");
dt_state << New Column("Dummy", Numeric, "Continuous", Format("Best", 12));
dt_state:Abbreviations << Set Property("Link ID", 1);
dt:State << Set Property("Link Reference", Reference Table(dt_state));
dt << group columns("xy", {:X, :y});
dt << group columns("pollutants", :Ozone :: :Lead);
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
For Each({grp, ig}, groups_list,
cols = Transform Each({colweirdness}, dt << get column group(grp), AsColumn(dt, colweirdness) << get name);
For Each({colname, ic}, cols,
If(colname == match_col,
try(dt << rename column group(grp, new_name));
)
);
);